Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package co.streamx.fluent.SQL;
import static co.streamx.fluent.SQL.Directives.subQuery;
import static co.streamx.fluent.SQL.SQL.FROM;
import static co.streamx.fluent.SQL.SQL.OFFSET;
import static co.streamx.fluent.SQL.SQL.SELECT;
import static co.streamx.fluent.SQL.ScalarFunctions.COALESCE;
import java.util.Collection;
public interface Library {
/**
* Translates to {@link ScalarFunctions#COALESCE(Comparable...)}. Use vendor specific variant if preferred.
*/
static > T ISNULL(T expression1,
T expression2) {
return COALESCE(expression1, expression2);
}
/**
* Translates to {@link SQL#OFFSET(int) OFFSET(0).ROWS().FETCH_NEXT(rowCount).ROWS_ONLY()}. Use vendor specific
* variant if preferred.
*/
static Clause LIMIT(int rowCount) {
return LIMIT(0, rowCount);
}
/**
* Translates to {@link SQL#OFFSET(int) OFFSET(offset).ROWS().FETCH_NEXT(rowCount).ROWS_ONLY()}. Use vendor specific
* variant if preferred.
*/
static Clause LIMIT(int offset,
int rowCount) {
return OFFSET(offset).ROWS().FETCH_NEXT(rowCount).ROWS_ONLY();
}
/**
* Translates to {@link SQL#OFFSET(int) OFFSET(offset).ROWS().FETCH_NEXT(rowCount).ROWS_ONLY()}. Use vendor specific
* variant if preferred.
*/
static Clause LIMIT_WITH_TIES(int offset,
int rowCount) {
return OFFSET(offset).ROWS().FETCH_NEXT(rowCount).ROWS_WITH_TIES();
}
/**
* Translates to {@code COUNT(Keywords.ASTERISK)},
* which translates to {@code COUNT(*)}
*/
static int COUNT() {
return AggregateFunctions.COUNT(Keywords.ASTERISK);
}
interface SafeCollection> extends Collection {
boolean contains(T o);
}
/**
* Performs a sub-query {@code SELECT FROM }. Since the result is a table with a single column,
* it's acceptable by operators such as {@link Operators#IN(Comparable, Collection) IN} and can be represented as
* Java {@link Collection}.
*
*
* Out of the box FluentJPA maps {@link Collection#isEmpty()}, {@link Collection#size()} and
* {@link Collection#contains(Object)} to the corresponding SQL functions ({@link Operators#EXISTS(Object) !EXISTS},
* {@link AggregateFunctions#COUNT(Comparable) COUNT} and {@link Operators#IN(Comparable, Collection) IN}).
*
* @return {@code Collection}
*/
static
>... fields) {
// return Arrays.stream(fields).map(field -> field.apply(tableRef)).toArray(Comparable[]::new);
// }
/**
* Performs a scalar sub-query {@code SELECT FROM }. If the query returns a scalar, that is a
* single row/column result, SQL implicitly casts it to that value. This function facilitates this behavior to Java.
*
* @return {@code FIELD}
*/
static
> FIELD pick(TABLE tableRef,
FIELD field) {
return subQuery(() -> {
SELECT(field);
FROM(tableRef);
});
}
/**
* Performs a sub-query {@code SELECT FROM }. Assuming there is a single row result, SQL
* implicitly creates a ROW Constructor value, which is abstracted with {@link UnboundRecord}. This function
* facilitates this behavior to Java.
*
* @return {@link UnboundRecord}
*/
@SafeVarargs
static R pickRow(Object tableRef,
Comparable>... fields) {
return subQuery(() -> {
SELECT(fields);
FROM(tableRef);
});
}
static , T1 extends Comparable super T1>> R pickRow(Object tableRef,
T1 expression) {
return subQuery(() -> {
SELECT(expression);
FROM(tableRef);
});
}
static , T1 extends Comparable super T1>, T2 extends Comparable super T2>> R pickRow(Object tableRef,
T1 expression1,
T2 expression2) {
return subQuery(() -> {
SELECT(expression1, expression2);
FROM(tableRef);
});
}
static , T1 extends Comparable super T1>, T2 extends Comparable super T2>, T3 extends Comparable super T3>> R pickRow(Object tableRef,
T1 expression1,
T2 expression2,
T3 expression3) {
return subQuery(() -> {
SELECT(expression1, expression2, expression3);
FROM(tableRef);
});
}
static , T1 extends Comparable super T1>, T2 extends Comparable super T2>, T3 extends Comparable super T3>, T4 extends Comparable super T4>> R pickRow(Object tableRef,
T1 expression1,
T2 expression2,
T3 expression3,
T4 expression4) {
return subQuery(() -> {
SELECT(expression1, expression2, expression3, expression4);
FROM(tableRef);
});
}
/**
* A shortcut for
*
*
* {@code SELECT();
* FROM();}
*
*
* which translates to {@code SELECT tableRef.* FROM tableRef}
*/
static void selectAll(Object tableRef) {
SELECT(tableRef);
FROM(tableRef);
}
/**
* A shortcut for
*
*