Search in sources :

Example 6 with RelationshipImpl

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

the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithSorting.

@Test
public void testSubCollectionFetchWithSorting() {
    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).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 " + "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)

Example 7 with RelationshipImpl

use of com.yahoo.elide.datastores.jpql.query.RelationshipImpl 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 8 with RelationshipImpl

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

the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithSortingAndFilters.

@Test
public void testSubCollectionFetchWithSortingAndFilters() {
    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);
    Map<String, Sorting.SortOrder> sorting = new HashMap<>();
    sorting.put(TITLE, Sorting.SortOrder.asc);
    EntityProjection entityProjection = EntityProjection.builder().type(Book.class).filterExpression(publisherNamePredicate).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_Book_publisher.name IN (:publisher_name_XXX) AND example_Author__fetch=:example_Author__fetch order by example_Book.title asc";
    String actual = query.getQueryText();
    actual = actual.replaceFirst(":publisher_name_\\w+", ":publisher_name_XXX");
    actual = actual.trim().replaceAll(" +", " ");
    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) HashMap(java.util.HashMap) Publisher(example.Publisher) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) 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) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) Test(org.junit.jupiter.api.Test)

Example 9 with RelationshipImpl

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

the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetch.

@Test
public void testSubCollectionFetch() {
    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().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();
    assertNull(query);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) SubCollectionFetchQueryBuilder(com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder) Book(example.Book) Relationship(com.yahoo.elide.core.request.Relationship) Author(example.Author) RelationshipImpl(com.yahoo.elide.datastores.jpql.query.RelationshipImpl) Test(org.junit.jupiter.api.Test)

Example 10 with RelationshipImpl

use of com.yahoo.elide.datastores.jpql.query.RelationshipImpl 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)

Aggregations

RelationshipImpl (com.yahoo.elide.datastores.jpql.query.RelationshipImpl)13 EntityProjection (com.yahoo.elide.core.request.EntityProjection)12 Relationship (com.yahoo.elide.core.request.Relationship)12 Book (example.Book)12 Test (org.junit.jupiter.api.Test)12 Author (example.Author)11 SubCollectionFetchQueryBuilder (com.yahoo.elide.datastores.jpql.query.SubCollectionFetchQueryBuilder)9 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)5 HashMap (java.util.HashMap)5 SubCollectionPageTotalsQueryBuilder (com.yahoo.elide.datastores.jpql.query.SubCollectionPageTotalsQueryBuilder)4 Publisher (example.Publisher)4 Path (com.yahoo.elide.core.Path)3 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)3 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)3 PaginationImpl (com.yahoo.elide.core.pagination.PaginationImpl)2 Pagination (com.yahoo.elide.core.request.Pagination)2 Sorting (com.yahoo.elide.core.request.Sorting)2 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)1 DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1