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.
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 static java.util.Objects.requireNonNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Parameter binder which supports each collection element binding as stand
* alone parameter and for each parameter there is ? created in SQL.
*
*
* Template sizes has to be defined, so result SQL will not create too much
* unique statements and binded parameter count will be one of defined.
*
*
* Binder will throw an error if collection size will exceed largest template
* size and usually there is some kind of limit for SQL server too. If
* collection is too big, use some other technique like temporary table.
*
*
* It is possible to supply mapper function for parameter unwrapping or
* use default build-in "for all collections". Null value is
* considered as single parameter and is processed as one, so to have some other
* behavior (error perhaps) use custom mapper function, where passed
* collection parameters can be wrapped in some special class.
*
*
* Use static {@link #builder()} for creating binder instances.
*
*/
public class ParameterBinderWithCollectionSupport extends ParameterBinderDefaultImpl {
private static final Function, ?> LAST_VALUE = parameters -> {
if (parameters instanceof List) {
List> list = (List>) parameters;
if (list.isEmpty()) {
throw new QueryBuildException(
"Can't get last value of collection for binder with collection support! Collection is empty. Use some conditional requirements to add this SQL clause!");
}
return list.get(list.size() - 1);
} else {
Iterator> iterator = parameters.iterator();
if (!iterator.hasNext()) {
throw new QueryBuildException(
"Can't get last value of collection for binder with collection support! Collection is empty. Use some conditional requirements to add this SQL clause!");
}
while (true) {
Object current = iterator.next();
if (!iterator.hasNext()) {
return current;
}
}
}
};
private static final Function, ?> NULL_VALUE = parameters -> null;
private static final Function