com.jaregu.database.queries.building.ToOrderedQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of queries Show documentation
Show all versions of queries Show documentation
Java based SQL templating project. Store your queries in *.sql files and build queries for execution. Supports simple expressions and conditional clauses and interface proxying for java-sql bridge.
package com.jaregu.database.queries.building;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import com.jaregu.database.queries.dialect.Dialect;
import com.jaregu.database.queries.dialect.Orderable;
public interface ToOrderedQuery {
/**
* Returns new query which has added ORDER BY
clause using
* configured ({@link Dialect}) implementation
*
* See {@link Dialect#toOrderedQuery(Query, Orderable)}
*/
Query toOrderedQuery(Orderable orderable);
/**
* Returns new query which has added ORDER BY
clause using
* configured ({@link Dialect}) implementation.
*
* See {@link Dialect#toOrderedQuery(Query, Orderable)}
*/
default Query toOrderedQuery(String... orderByItems) {
return toOrderedQuery(orderByItems == null ? () -> Collections.emptyList() : () -> Arrays.asList(orderByItems));
}
/**
* Returns new query which has added ORDER BY
clause using
* configured ({@link Dialect}) implementation
*
* See {@link Dialect#toOrderedQuery(Query, Orderable)}
*/
default Query toOrderedQuery(Iterable orderByItems) {
return toOrderedQuery(orderByItems == null ? () -> Collections.emptyList()
: () -> StreamSupport.stream(orderByItems.spliterator(), false).collect(Collectors.toList()));
}
}