Improve path in collection handling

This commit is contained in:
Timo Westkämper 2014-10-11 00:57:14 +03:00
parent 907d97fb50
commit e83c592d06
2 changed files with 14 additions and 5 deletions

View File

@ -745,7 +745,7 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
append(")");
int size = ((Collection) constant).size() - 1;
Path<?> lastPath = constantPaths.get(constantPaths.size() - 1);
Path<?> lastPath = constantPaths.isEmpty() ? null : constantPaths.get(constantPaths.size() - 1);
for (int i = 0; i < size; i++) {
constantPaths.add(lastPath);
}
@ -832,10 +832,13 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
&& args.get(0) instanceof Path<?>
&& args.get(1) instanceof Constant<?>
&& operator != Ops.NUMCAST) {
for (Element element : templates.getTemplate(operator).getElements()) {
if (element instanceof Template.ByIndex && ((Template.ByIndex)element).getIndex() == 1) {
constantPaths.add((Path<?>)args.get(0));
break;
Object constant = ((Constant)args.get(1)).getConstant();
if (!Collection.class.isInstance(constant) || !((Collection)constant).isEmpty()) {
for (Element element : templates.getTemplate(operator).getElements()) {
if (element instanceof Template.ByIndex && ((Template.ByIndex)element).getIndex() == 1) {
constantPaths.add((Path<?>)args.get(0));
break;
}
}
}
}

View File

@ -594,6 +594,12 @@ public class SelectBase extends AbstractBaseTest {
query().from(employee).where(employee.id.in(Arrays.asList(1,2))).list(employee);
}
@Test
@IncludeIn(H2)
public void In_Empty() {
query().from(employee).where(employee.id.in(ImmutableList.<Integer>of())).list(employee);
}
@Test
public void Inner_Join() throws SQLException {
query().from(employee).innerJoin(employee2)