Search in sources :

Example 26 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class RootCollectionFetchQueryBuilderTest method testRootFetchWithSortingAndFilters.

@Test
public void testRootFetchWithSortingAndFilters() {
    Map<String, Sorting.SortOrder> sorting = new HashMap<>();
    sorting.put(TITLE, Sorting.SortOrder.asc);
    Path.PathElement idPath = new Path.PathElement(Book.class, Chapter.class, "id");
    FilterPredicate idPredicate = new InPredicate(idPath, 1);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).filterExpression(idPredicate).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Book AS example_Book" + " WHERE example_Book.id IN (:id_XXX) order by example_Book.title asc";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
    assertEquals(expected, actual);
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) HashMap(java.util.HashMap) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 27 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class RootCollectionFetchQueryBuilderTest method testRootFetchWithToOneRelationIncluded.

@Test
public void testRootFetchWithToOneRelationIncluded() {
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).relationship(Relationship.builder().name(PUBLISHER).projection(EntityProjection.builder().type(Publisher.class).build()).build()).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Book AS example_Book LEFT JOIN FETCH example_Book.publisher";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Publisher(example.Publisher) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 28 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class RootCollectionFetchQueryBuilderTest method testSortingWithJoin.

@Test
public void testSortingWithJoin() {
    Map<String, Sorting.SortOrder> sorting = new HashMap<>();
    sorting.put(PUBLISHER + PERIOD + NAME, Sorting.SortOrder.asc);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Book AS example_Book " + "LEFT JOIN example_Book.publisher example_Book_publisher " + "order by example_Book_publisher.name asc";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) HashMap(java.util.HashMap) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 29 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class RootCollectionFetchQueryBuilderTest method testRootFetchWithSorting.

@Test
public void testRootFetchWithSorting() {
    Map<String, Sorting.SortOrder> sorting = new HashMap<>();
    sorting.put(TITLE, Sorting.SortOrder.asc);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Book AS example_Book " + "order by example_Book.title asc";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) HashMap(java.util.HashMap) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 30 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class DataStoreSupportsFilteringTest method testNgramJustRight.

@Test
public void testNgramJustRight() throws Exception {
    DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
    FilterPredicate filter = (FilterPredicate) filterParser.parseFilterExpression("description==*ruabc*", 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)

Aggregations

EntityProjection (com.yahoo.elide.core.request.EntityProjection)108 Test (org.junit.jupiter.api.Test)90 Book (example.Book)41 RequestScope (com.yahoo.elide.core.RequestScope)27 Author (example.Author)27 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)22 Publisher (example.Publisher)22 Relationship (com.yahoo.elide.core.request.Relationship)19 Path (com.yahoo.elide.core.Path)18 TestRequestScope (com.yahoo.elide.core.TestRequestScope)18 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)18 HashMap (java.util.HashMap)18 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)18 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)16 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)15 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)15 Collection (java.util.Collection)15 LinkedHashSet (java.util.LinkedHashSet)14 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)13 Editor (example.Editor)13