Fix ListQueryMapper

This commit is contained in:
Travis Burtrum 2018-10-11 00:33:52 -04:00
parent 1a161d7214
commit a378e640ae

View File

@ -58,16 +58,24 @@ public class ListQueryMapper extends QueryMapper {
}
protected final QueryMapper delegate;
protected final boolean closeDelegate;
protected final InList inList;
public static final String inListReplace = "{inList}";
private ListQueryMapper(Connection conn, String jndiName, Factory<Connection> factory, QueryMapper delegate, ResultSetMapper cm, InList inList) {
this.inList = inList.instance(conn);
this.delegate = delegate == null ? new QueryMapper(conn, jndiName, factory, cm) :
this.closeDelegate = delegate == null;
this.delegate = this.closeDelegate ? new QueryMapper(conn, jndiName, factory, cm) :
(delegate instanceof ListQueryMapper ? ((ListQueryMapper)delegate).delegate : delegate);
}
public ListQueryMapper(InList inList, QueryMapper delegate, boolean closeDelegate) {
this.delegate = delegate;
this.closeDelegate = closeDelegate;
this.inList = inList;
}
public ListQueryMapper(QueryMapper delegate, InList inList) {
this(null, null, null, delegate, null, inList);
}
@ -124,13 +132,20 @@ public class ListQueryMapper extends QueryMapper {
this(factory, cm, defaultInList);
}
// todo: get rid of wrap, cause, how do you know to close it or not? :'(
public static ListQueryMapper wrap(final QueryMapper qm){
return qm instanceof ListQueryMapper ? (ListQueryMapper)qm : new ListQueryMapper(qm);
public static ListQueryMapper of(final Factory<QueryMapper> qmFactory, final InList inList) throws SQLException {
return new ListQueryMapper(inList, qmFactory.create(), true);
}
public static ListQueryMapper wrap(final QueryMapper qm, final InList inList){
return qm instanceof ListQueryMapper && ((ListQueryMapper)qm).inList == inList ? (ListQueryMapper)qm : new ListQueryMapper(qm, inList);
public static ListQueryMapper of(final QueryMapper qm, final InList inList) {
return new ListQueryMapper(inList, qm, false);
}
public static ListQueryMapper of(final Factory<QueryMapper> qmFactory) throws SQLException {
return of(qmFactory, defaultInList);
}
public static ListQueryMapper of(final QueryMapper qm) {
return of(qm, defaultInList);
}
public <T> InList.InListObject inList(final String columnName, final Collection<T> values) throws SQLException {
@ -218,7 +233,8 @@ public class ListQueryMapper extends QueryMapper {
@Override
public void close() {
delegate.close();
if(closeDelegate)
delegate.close();
}
// and these are standard
@ -312,7 +328,7 @@ public class ListQueryMapper extends QueryMapper {
return delegate.insertGetGeneratedKeyType(prepareSql(sql, bindObjects), psf, typeReference, bindObjects);
}
// DO NOT EDIT BELOW THIS LINE, OR CHANGE THIS COMMENT, CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh
// DO NOT EDIT BELOW THIS LINE, OR CHANGE THIS COMMENT, CODE AUTOMATICALLY GENERATED BY genQueryMapper.sh
@Override
public <T> T toObject(PreparedStatement ps, Class<T> componentType, final Object... bindObjects) throws SQLException {