List activation

23 views
Skip to first unread message

Sydney

unread,
Apr 26, 2012, 5:31:50 PM4/26/12
to twig-p...@googlegroups.com
I load a top-level object with no activation (depth 0). Then I tried to activate the second-level object I got an exception.

        Fan fan = new Fan();
        fan.setName("Me");
        Concert concert = new Concert(new Date(), new CurrencyAmount(
                CurrencyType.CHF, 25.0));
        Band britney = new Band("Britney", new CurrencyAmount(CurrencyType.CHF,
                25.0));
        concert.getBands().add(britney);
        fan.getConcerts().add(concert);
        FanDao fanDao = new FanDao();
        fanDao.create(fan);

        ObjectDatastore datastore = new AnnotationObjectDatastore(false);
        Fan datastoreFan = datastore.find().type(Fan.class).activate(0).addFilter(
                "id", FilterOperator.EQUAL, fan.getId()).returnUnique().now();
        assertTrue(datastoreFan.getName().equals("Me"));
        assertTrue(datastoreFan.getConcerts().size() == 1);
        assertTrue(datastoreFan.getConcerts().get(0).getId() != null);
        assertTrue(datastoreFan.getConcerts().get(0).getPrice() == null);
        // Try to activate all the concerts (see stack trace)
        datastore.activateAll(datastoreFan.getConcerts());
        assertTrue(datastoreFan.getConcerts().get(0).getPrice() != null);
        // Try to activate only the first concert (same stack trace)
        datastore.activate(datastoreFan.getConcerts().get(0));
        assertTrue(datastoreFan.getConcerts().get(0).getPrice() != null);

java.lang.IllegalStateException: Problem translating field private final java.util.List com.test.model.Concert.bands with properties [[SimpleProperty value=[com_test_model_Band(201)] path=bands indexed=false]]
at com.google.code.twig.translator.FieldTranslator.decodeField(FieldTranslator.java:157)
at com.google.code.twig.standard.TranslatorObjectDatastore$ObjectFieldTranslator.decodeField(TranslatorObjectDatastore.java:963)
at com.google.code.twig.translator.FieldTranslator.decode(FieldTranslator.java:122)
at com.google.code.twig.standard.StandardDecodeCommand.entityToInstance(StandardDecodeCommand.java:119)
at com.google.code.twig.standard.StandardDecodeCommand.keysToInstances(StandardDecodeCommand.java:235)
at com.google.code.twig.standard.StandardUntypedMultipleLoadCommand.now(StandardUntypedMultipleLoadCommand.java:20)
at com.google.code.twig.standard.TranslatorObjectDatastore.doRefreshActivate(TranslatorObjectDatastore.java:731)
at com.google.code.twig.standard.TranslatorObjectDatastore.activateAll(TranslatorObjectDatastore.java:768)
at com.test.MyConcurrencyTest.testAssociation(MyConcurrencyTest.java:73)
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:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
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:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
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)
Caused by: java.lang.ClassCastException: com.test.model.Concert cannot be cast to java.util.List
at com.google.code.twig.standard.CollectionTranslator.createCollection(CollectionTranslator.java:141)
at com.google.code.twig.standard.CollectionTranslator.decode(CollectionTranslator.java:47)
at com.google.code.twig.translator.ChainedTranslator.decode(ChainedTranslator.java:75)
at com.google.code.twig.translator.FieldTranslator.decodeField(FieldTranslator.java:152)
... 33 more

I also wonder if it's possible after you loaded an instance to activate until a certain depth. For instance you get a fan, then you want to activate the concert but not the bands. 

Sydney

unread,
Apr 27, 2012, 5:35:23 PM4/27/12
to twig-p...@googlegroups.com
I looked at the code and the faulty method is in CollectionTranslator

protected List<Object> createCollection(Type type)
{
if (datastore.refresh != null)
{
@SuppressWarnings("unchecked")
List<Object> result = (List<Object>) datastore.refresh;
datastore.refresh = null;
return result;
}
else
{
return new ArrayList<Object>();
}
}

when trying to cast the datastore.refresh into a list of Object. datastore.refresh contains a Concert. 

        datastore = new AnnotationObjectDatastore(false);
        Fan datastoreFan = datastore.find().type(Fan.class).activate(0).addFilter(
                "id", FilterOperator.EQUAL, fan.getId()).returnUnique().now();
        datastore.activate(datastoreFan.getConcerts().get(0));

I can send you a test if it's easier for you to find out the issue.

John Patterson

unread,
Apr 28, 2012, 12:31:25 AM4/28/12
to twig-p...@googlegroups.com
Yes you are right about the cause of the problem.  This is due to activation / refresh of an instance and a test case would really help!

Sydney

unread,
Apr 28, 2012, 3:37:16 AM4/28/12
to twig-p...@googlegroups.com
It's a maven project, the test is in com.test.ActivationBugTest. The test is testAssociation.
activation-bug.zip

John Patterson

unread,
Apr 28, 2012, 5:45:14 AM4/28/12
to twig-p...@googlegroups.com
Great, thanks for that.  You test shows an error in the new activation code.

This code was changed to make the new @Denormalise feature work.  I am making a fix now that actually seems to be simplifying the code :)

Although this large check in seems to have broken some existing features, in the long run it much better for me to be using the same code base as is publicly available.  As soon as this stabilises I will write up some of the new features including @Denormalise and @Cache and the improvements to activation.

<activation-bug.zip>

John Patterson

unread,
Apr 28, 2012, 6:03:58 AM4/28/12
to twig-p...@googlegroups.com
Sydney, your test case is now passing with the code just pushed to the repo.


Thanks again for the great test case!

Sydney

unread,
Apr 28, 2012, 8:22:42 AM4/28/12
to twig-p...@googlegroups.com
I tested the new version and it's working. Thanks for the quick fix.
Reply all
Reply to author
Forward
0 new messages