2015-04-29 12:03:35 -04:00
|
|
|
package com.moparisthebest.jdbc;
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.util.*;
|
|
|
|
|
2018-05-22 00:08:14 -04:00
|
|
|
import static com.moparisthebest.jdbc.util.InListUtil.defaultMaxSize;
|
2018-05-21 01:05:53 -04:00
|
|
|
import static com.moparisthebest.jdbc.util.InListUtil.toInList;
|
2018-05-22 23:09:57 -04:00
|
|
|
import static com.moparisthebest.jdbc.util.InListUtil.toNotInList;
|
2018-05-21 01:05:53 -04:00
|
|
|
|
2015-04-29 12:03:35 -04:00
|
|
|
/**
|
|
|
|
* Created by mopar on 4/29/15.
|
|
|
|
*/
|
|
|
|
public class BindInList implements InList {
|
|
|
|
|
|
|
|
private static final InList instance = new BindInList();
|
|
|
|
|
|
|
|
public static InList instance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private final int maxSize;
|
|
|
|
|
|
|
|
public BindInList(final int maxSize) {
|
|
|
|
this.maxSize = maxSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected BindInList() {
|
|
|
|
this(defaultMaxSize);
|
|
|
|
}
|
|
|
|
|
2018-05-23 23:41:19 -04:00
|
|
|
@Override
|
|
|
|
public InList instance(Connection conn) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-04-29 12:03:35 -04:00
|
|
|
public <T> InListObject inList(final Connection conn, final String columnName, final Collection<T> values) {
|
2019-02-07 01:09:15 -05:00
|
|
|
return values == null || values.isEmpty() ? InListObject.inEmpty : new InListObject(
|
2018-05-21 01:05:53 -04:00
|
|
|
toInList(columnName, values, this.maxSize),
|
2019-02-07 01:09:15 -05:00
|
|
|
values
|
2015-04-29 12:03:35 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-22 23:09:57 -04:00
|
|
|
public <T> InListObject notInList(final Connection conn, final String columnName, final Collection<T> values) {
|
2019-02-07 01:09:15 -05:00
|
|
|
return values == null || values.isEmpty() ? InListObject.notInEmpty : new InListObject(
|
2018-05-22 23:09:57 -04:00
|
|
|
toNotInList(columnName, values, this.maxSize),
|
2019-02-07 01:09:15 -05:00
|
|
|
values
|
2018-05-22 23:09:57 -04:00
|
|
|
);
|
|
|
|
}
|
2015-04-29 12:03:35 -04:00
|
|
|
}
|