use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class AbstractHQLQueryBuilderTest method testSortClauseWithPrefix.
@Test
public void testSortClauseWithPrefix() {
Map<String, Sorting.SortOrder> sorting = new LinkedHashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
sorting.put(GENRE, Sorting.SortOrder.desc);
String actual = getSortClause(new SortingImpl(sorting, Book.class, dictionary));
String expected = " order by example_Book.title asc,example_Book.genre desc";
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.sort.SortingImpl 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);
}
use of com.yahoo.elide.core.sort.SortingImpl 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);
}
use of com.yahoo.elide.core.sort.SortingImpl 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);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class DataStoreLoadTest method testPaginationPageTwo.
@Test
public void testPaginationPageTwo() throws Exception {
DataStoreTransaction testTransaction = searchStore.beginReadTransaction();
Map<String, Sorting.SortOrder> sortRules = new HashMap<>();
sortRules.put("name", Sorting.SortOrder.desc);
sortRules.put("modifiedDate", Sorting.SortOrder.asc);
Sorting sorting = new SortingImpl(sortRules, Item.class, dictionary);
PaginationImpl pagination = new PaginationImpl(Item.class, 1, 1, PaginationImpl.DEFAULT_PAGE_LIMIT, PaginationImpl.MAX_PAGE_LIMIT, true, false);
FilterExpression filter = filterParser.parseFilterExpression("name==cymbal*", ClassType.of(Item.class), false);
Iterable<Object> loaded = testTransaction.loadObjects(EntityProjection.builder().type(Item.class).filterExpression(filter).sorting(sorting).pagination(pagination).build(), mockScope);
assertListMatches(loaded, Lists.newArrayList(5L));
assertEquals(pagination.getPageTotals(), 3);
verify(wrappedTransaction, never()).loadObjects(any(), any());
}
Aggregations