Search in sources :

Example 16 with EntityProjection

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

the class RootCollectionPageTotalsQueryBuilderTest method testRootFetch.

@Test
public void testRootFetch() {
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).build();
    RootCollectionPageTotalsQueryBuilder builder = new RootCollectionPageTotalsQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT COUNT(DISTINCT example_Book) " + "FROM example.Book AS example_Book";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) Book(example.Book) Test(org.junit.jupiter.api.Test)

Example 17 with EntityProjection

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

the class RootCollectionPageTotalsQueryBuilderTest method testRootFetchWithSorting.

@Test
public void testRootFetchWithSorting() {
    Sorting sorting = mock(Sorting.class);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(sorting).build();
    TestQueryWrapper query = (TestQueryWrapper) new RootCollectionPageTotalsQueryBuilder(entityProjection, dictionary, new TestSessionWrapper()).build();
    String expected = "SELECT COUNT(DISTINCT example_Book) FROM example.Book AS example_Book";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) Sorting(com.yahoo.elide.core.request.Sorting) Test(org.junit.jupiter.api.Test)

Example 18 with EntityProjection

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

the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithJoinFilter.

@Test
public void testSubCollectionFetchWithJoinFilter() {
    Author author = new Author();
    author.setId(1L);
    Book book = new Book();
    book.setId(2);
    List<Path.PathElement> publisherNamePath = Arrays.asList(new Path.PathElement(Book.class, Publisher.class, PUBLISHER), new Path.PathElement(Publisher.class, String.class, NAME));
    FilterPredicate publisherNamePredicate = new InPredicate(new Path(publisherNamePath), PUB1);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).filterExpression(publisherNamePredicate).build();
    Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
    RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
    SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book " + "LEFT JOIN example_Book.publisher example_Book_publisher  " + "WHERE example_Book_publisher.name IN (:books_publisher_name_XXX) AND example_Author__fetch=:example_Author__fetch ";
    String actual = query.getQueryText();
    actual = actual.replaceFirst(":publisher_name_\\w+_\\w+", ":books_publisher_name_XXX");
    assertEquals(expected, actual);
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) SubCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder) Publisher(example.Publisher) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 19 with EntityProjection

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

the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithRelationshipSorting.

@Test
public void testSubCollectionFetchWithRelationshipSorting() {
    Author author = new Author();
    author.setId(1L);
    Book book = new Book();
    book.setId(2);
    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();
    Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
    RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
    SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book " + "LEFT JOIN example_Book.publisher example_Book_publisher " + "WHERE example_Author__fetch=:example_Author__fetch order by example_Book_publisher.name asc";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) SubCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder) HashMap(java.util.HashMap) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) Test(org.junit.jupiter.api.Test)

Example 20 with EntityProjection

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

the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithIncludedRelation.

@Test
public void testSubCollectionFetchWithIncludedRelation() {
    Author author = new Author();
    author.setId(1L);
    Book book = new Book();
    book.setId(2);
    Map<String, Sorting.SortOrder> sorting = new HashMap<>();
    sorting.put(TITLE, Sorting.SortOrder.asc);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).relationship(Relationship.builder().name(PUBLISHER).projection(EntityProjection.builder().type(Publisher.class).build()).build()).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
    Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
    RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
    SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book LEFT JOIN FETCH example_Book.publisher " + "WHERE example_Author__fetch=:example_Author__fetch 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) SubCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder) HashMap(java.util.HashMap) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) 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