devng / twig-persist

Automatically exported from code.google.com/p/twig-persist
0 stars 0 forks source link

Too many queries Exception when trying to use returnCount() in RootFindCommand<T> #40

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
@Test
public void testOr() {
    ds.storeAll(getUserEntities());
        RootFindCommand<UserEntity> root = ds.find().type(UserEntity.class);

        BranchFindCommand branch = root.branch(MergeOperator.OR);
        branch.addChildCommand().addFilter("firstName", FilterOperator.EQUAL, "a");
        branch.addChildCommand().addFilter("lastName", FilterOperator.EQUAL, "b");

        assertEquals(4, (int) root.returnCount().now()); // IllegalStateException: Too many queries
        assertEquals(4, Iterators.size(root.now())); // works fine
}

java.lang.IllegalStateException: Too many queries
    at com.google.code.twig.standard.StandardRootFindCommand$2.now(StandardRootFindCommand.java:234)
    at com.google.code.twig.standard.StandardRootFindCommand$2.now(StandardRootFindCommand.java:227)
    at fi.turkuamk.examples.tests.LocalDatastoreTest.testOr(LocalDatastoreTest.java:111)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Original issue reported on code.google.com by tero.nur...@gmail.com on 21 Oct 2010 at 9:15

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Affected version twig-persist-2.0-beta2.jar

Original comment by tero.nur...@gmail.com on 21 Oct 2010 at 9:19

GoogleCodeExporter commented 8 years ago
I think throwing an exception here is correct.  The datastore can only perform 
a count operation on a single command but your test creates two commands.  The 
only way to handle this is by running the query and manually counting the 
results returned.  Not very efficient.  If you were to do this you could stop 
Twig from actually crating entities by using a "Restriction" 
.restrict(COUNT_ENTITIES_BUT_DO_NOT_ACCEPT)

I've marked as WontFix for now, but if you can suggest a workable solution I 
can change it to accepted.

Original comment by jdpatterson on 22 Oct 2010 at 5:50

GoogleCodeExporter commented 8 years ago
I see. Then I need to go with the manual counting as in the @Tests. Do you have 
some plans for updating the wiki about features coming with version 2.0. I was 
searching the groups and junit tests about "restriction" and BranchFindCommand 
but they really didn't open up.

Original comment by tero.nur...@gmail.com on 22 Oct 2010 at 5:19