Search in sources :

Example 76 with EntityProjection

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

the class RootCollectionFetchQueryBuilderTest method testDistinctRootFetchWithToManyJoinFilterAndPagination.

@Test
public void testDistinctRootFetchWithToManyJoinFilterAndPagination() throws ParseException {
    final Pagination pagination = new PaginationImpl(Book.class, 0, 10, 10, 10, false, false);
    final FilterExpression titlePredicate = filterParser.parseFilterExpression("books.chapters.title=in=('ABC','DEF')", ClassType.of(Author.class), true);
    final FilterExpression publisherNamePredicate = filterParser.parseFilterExpression("books.publisher.name=in='Pub1'", ClassType.of(Author.class), true);
    OrFilterExpression expression = new OrFilterExpression(titlePredicate, publisherNamePredicate);
    EntityProjection entityProjection = EntityProjection.builder().type(Author.class).pagination(pagination).filterExpression(expression).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT DISTINCT example_Author FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.chapters example_Author_books_chapters " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_chapters.title IN (:books_chapters_title_XXX, :books_chapters_title_XXX) " + "OR example_Author_books_publisher.name IN (:books_publisher_name_XXX))";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
    actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
    actual = actual.replaceFirst(":books_publisher_name_\\w\\w\\w\\w+", ":books_publisher_name_XXX");
    assertEquals(expected, actual);
}
Also used : Pagination(com.yahoo.elide.core.request.Pagination) EntityProjection(com.yahoo.elide.core.request.EntityProjection) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Author(example.Author) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 77 with EntityProjection

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

the class RootCollectionFetchQueryBuilderTest method testRootFetchWithJoinFilter.

@Test
public void testRootFetchWithJoinFilter() throws ParseException {
    final FilterExpression titlePredicate = filterParser.parseFilterExpression("books.chapters.title=in=('ABC','DEF')", ClassType.of(Author.class), true);
    final FilterExpression publisherNamePredicate = filterParser.parseFilterExpression("books.publisher.name=in='Pub1'", ClassType.of(Author.class), true);
    OrFilterExpression expression = new OrFilterExpression(titlePredicate, publisherNamePredicate);
    EntityProjection entityProjection = EntityProjection.builder().type(Author.class).filterExpression(expression).build();
    RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT example_Author FROM example.Author AS example_Author  " + "LEFT JOIN example_Author.books example_Author_books  " + "LEFT JOIN example_Author_books.chapters example_Author_books_chapters   " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher   " + "WHERE (example_Author_books_chapters.title IN (:books_chapters_title_XXX, :books_chapters_title_XXX) " + "OR example_Author_books_publisher.name IN (:books_publisher_name_XXX)) ";
    String actual = query.getQueryText();
    actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
    actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
    actual = actual.replaceFirst(":books_publisher_name_\\w\\w\\w\\w+", ":books_publisher_name_XXX");
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Author(example.Author) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RootCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionFetchQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 78 with EntityProjection

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

the class RootCollectionFetchQueryBuilderTest method testRootFetchWithRelationshipSortingAndFilters.

@Test
public void testRootFetchWithRelationshipSortingAndFilters() {
    Map<String, Sorting.SortOrder> sorting = new HashMap<>();
    sorting.put(PUBLISHER + PERIOD + EDITOR + PERIOD + FIRSTNAME, Sorting.SortOrder.desc);
    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" + " LEFT JOIN example_Book.publisher example_Book_publisher" + " LEFT JOIN example_Book_publisher.editor example_Book_publisher_editor" + " WHERE example_Book.id IN (:id_XXX)" + " order by example_Book_publisher_editor.firstName desc";
    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 79 with EntityProjection

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

the class RootCollectionPageTotalsQueryBuilderTest method testRootFetchWithJoinFilter.

@Test
public void testRootFetchWithJoinFilter() {
    List<Path.PathElement> chapterTitlePath = Arrays.asList(new Path.PathElement(Author.class, Book.class, BOOKS), new Path.PathElement(Book.class, Chapter.class, "chapters"), new Path.PathElement(Chapter.class, String.class, TITLE));
    FilterPredicate titlePredicate = new InPredicate(new Path(chapterTitlePath), "ABC", "DEF");
    List<Path.PathElement> publisherNamePath = Arrays.asList(new Path.PathElement(Author.class, Book.class, BOOKS), new Path.PathElement(Book.class, Publisher.class, PUBLISHER), new Path.PathElement(Publisher.class, String.class, "name"));
    FilterPredicate publisherNamePredicate = new InPredicate(new Path(publisherNamePath), "Pub1");
    OrFilterExpression expression = new OrFilterExpression(titlePredicate, publisherNamePredicate);
    EntityProjection entityProjection = EntityProjection.builder().type(Author.class).filterExpression(expression).build();
    RootCollectionPageTotalsQueryBuilder builder = new RootCollectionPageTotalsQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT COUNT(DISTINCT example_Author) FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.chapters example_Author_books_chapters " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_chapters.title IN " + "(:books_chapters_title_XXX, :books_chapters_title_XXX) " + "OR example_Author_books_publisher.name IN (:books_publisher_name_XXX))";
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
    actual = actual.replaceFirst(":books_chapters_title_\\w\\w\\w\\w+", ":books_chapters_title_XXX");
    actual = actual.replaceFirst(":books_publisher_name_\\w\\w\\w\\w+", ":books_publisher_name_XXX");
    assertEquals(expected, actual);
}
Also used : Path(com.yahoo.elide.core.Path) EntityProjection(com.yahoo.elide.core.request.EntityProjection) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) Chapter(example.Chapter) Publisher(example.Publisher) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Book(example.Book) Author(example.Author) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 80 with EntityProjection

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

the class RootCollectionPageTotalsQueryBuilderTest method testRootFetchWithPagination.

@Test
public void testRootFetchWithPagination() {
    PaginationImpl pagination = mock(PaginationImpl.class);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).pagination(pagination).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) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) RootCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.RootCollectionPageTotalsQueryBuilder) 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