All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaregu.database.queries.building.ToOrderedQuery Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.4.1
Show newest version
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()));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy