Search in sources :

Example 1 with SubCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder in project elide by yahoo.

the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotalsWithPagination.

@Test
public void testSubCollectionPageTotalsWithPagination() {
    Author author = new Author();
    author.setId(1L);
    Book book = new Book();
    book.setId(2);
    PaginationImpl pagination = mock(PaginationImpl.class);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).pagination(pagination).build();
    Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
    RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
    TestQueryWrapper query = (TestQueryWrapper) new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper()).build();
    String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "JOIN example_Author.books example_Author_books " + "WHERE example_Author.id IN (:id_XXX)";
    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) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) SubCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with SubCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder in project elide by yahoo.

the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotalsWithSorting.

@Test
public void testSubCollectionPageTotalsWithSorting() {
    Author author = new Author();
    author.setId(1L);
    Book book = new Book();
    book.setId(2);
    Sorting sorting = mock(Sorting.class);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(sorting).build();
    Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
    RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
    TestQueryWrapper query = (TestQueryWrapper) new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper()).build();
    String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "JOIN example_Author.books example_Author_books " + "WHERE example_Author.id IN (:id_XXX)";
    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) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) Sorting(com.yahoo.elide.core.request.Sorting) SubCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with SubCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder in project elide by yahoo.

the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotalsWithJoinFilter.

@Test
public void testSubCollectionPageTotalsWithJoinFilter() {
    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);
    SubCollectionPageTotalsQueryBuilder builder = new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_publisher.name IN (:books_publisher_name_XXX) " + "AND example_Author.id IN (:id_XXX))";
    String actual = query.getQueryText();
    actual = actual.replaceFirst(":books_publisher_name_\\w+", ":books_publisher_name_XXX");
    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) 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) SubCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with SubCollectionPageTotalsQueryBuilder

use of com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder in project elide by yahoo.

the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotals.

@Test
public void testSubCollectionPageTotals() {
    Author author = new Author();
    author.setId(1L);
    Book book = new Book();
    book.setId(2);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).build();
    Relationship relationshipProjection = Relationship.builder().projection(entityProjection).name(BOOKS).build();
    RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
    SubCollectionPageTotalsQueryBuilder builder = new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper());
    TestQueryWrapper query = (TestQueryWrapper) builder.build();
    String actual = query.getQueryText();
    actual = actual.trim().replaceAll(" +", " ");
    actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
    String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "JOIN example_Author.books example_Author_books " + "WHERE example_Author.id IN (:id_XXX)";
    assertEquals(expected, actual);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) SubCollectionPageTotalsQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

EntityProjection (com.yahoo.elide.core.request.EntityProjection)4 Relationship (com.yahoo.elide.core.request.Relationship)4 RelationshipImpl (com.yahoo.elide.datastores.jpql.query.RelationshipImpl)4 SubCollectionPageTotalsQueryBuilder (com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder)4 Author (example.Author)4 Book (example.Book)4 Test (org.junit.jupiter.api.Test)4 Path (com.yahoo.elide.core.Path)1 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)1 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)1 PaginationImpl (com.yahoo.elide.core.pagination.PaginationImpl)1 Sorting (com.yahoo.elide.core.request.Sorting)1 Publisher (example.Publisher)1