Remove MAX_KEYS limit, added test.

We've had JDBC array support in Postgres for 5 years now, so I think we're
probably safe to assume it's working everywhere. Ha ha, I'm such an optimist.
This commit is contained in:
Michael Bayne
2014-10-02 14:30:11 -07:00
parent 62c17819f4
commit 190c38f8a8
2 changed files with 22 additions and 16 deletions
@@ -129,7 +129,7 @@ public abstract class KeySet<T extends PersistentRecord> extends WhereClause
return true; return true;
} }
return (obj instanceof EmptyKeySet<?>) && return (obj instanceof EmptyKeySet<?>) &&
_pClass.equals(((EmptyKeySet<?>)obj)._pClass); _pClass.equals(((EmptyKeySet<?>)obj)._pClass);
} }
@Override public int hashCode () { @Override public int hashCode () {
@@ -145,11 +145,6 @@ public abstract class KeySet<T extends PersistentRecord> extends WhereClause
{ {
public SingleKeySet (Class<T> pClass, Comparable<?>[] keys) { public SingleKeySet (Class<T> pClass, Comparable<?>[] keys) {
super(pClass); super(pClass);
// TODO: remove when we update to 1.6 and change Postgres In handling
if (keys.length > In.MAX_KEYS) {
throw new IllegalArgumentException(
"Cannot create where clause for more than " + In.MAX_KEYS + " keys at a time.");
}
_keys = keys; _keys = keys;
} }
@@ -4,18 +4,19 @@
package com.samskivert.depot; package com.samskivert.depot;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.samskivert.depot.annotation.Computed; import com.samskivert.depot.annotation.Computed;
import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.expression.SQLExpression;
import com.samskivert.depot.impl.operator.In;
import com.samskivert.depot.util.Builder2; import com.samskivert.depot.util.Builder2;
import com.samskivert.util.RandomUtil; import com.samskivert.util.RandomUtil;
@@ -76,7 +77,7 @@ public class QueryTest extends TestBase
assertEquals(CREATE_RECORDS, results.size()); assertEquals(CREATE_RECORDS, results.size());
for (float result : results) { for (float result : results) {
assertTrue("Age goes from [0,99) and awesomeness goes from [0.0,1.0), so their " + assertTrue("Age goes from [0,99) and awesomeness goes from [0.0,1.0), so their " +
"product should be [0.0,100), not " + result, result >= 0 && result < 100); "product should be [0.0,100), not " + result, result >= 0 && result < 100);
} }
assertEquals(CREATE_RECORDS, _repo.findAll(TestRecord.class).size()); assertEquals(CREATE_RECORDS, _repo.findAll(TestRecord.class).size());
@@ -85,13 +86,23 @@ public class QueryTest extends TestBase
_repo.from(TestRecord.class).whereTrue().delete(); _repo.from(TestRecord.class).whereTrue().delete();
assertEquals(0, _repo.findAll(TestRecord.class).size()); assertEquals(0, _repo.findAll(TestRecord.class).size());
}
// // TODO: try to break our In() clause @Test public void testMaxKeys () {
// Set<Integer> ids = Sets.newHashSet(); Set<Integer> ids = Sets.newHashSet();
// for (int ii = 1; ii <= In.MAX_KEYS*2+3; ii++) { int count = In.MAX_KEYS+3;
// ids.add(ii); for (int ii = 1; ii <= count; ii++) {
// } TestRecord record = createTestRecord(ii);
// _repo.deleteAll(TestRecord.class, KeySet.newSimpleKeySet(TestRecord.class, ids)); record.name = "Spam! " + ii;
record.age = RandomUtil.getInt(100);
record.awesomeness = RandomUtil.getFloat(1.0F);
record.homeTown = "Over there";
_repo.insert(record);
ids.add(ii);
}
assertEquals(count, _repo.from(TestRecord.class).selectCount());
_repo.deleteAll(TestRecord.class, KeySet.newSimpleKeySet(TestRecord.class, ids));
assertEquals(0, _repo.from(TestRecord.class).selectCount());
} }
@Test public void testLimitedDelete () @Test public void testLimitedDelete ()