devng / twig-persist

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

Filtering FindCommand with Enum values throw IllegalArgumentException #41

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
* Property types (at least Enum) which are translated for storing should also 
be translated when fetching
* Affected version: 2.0-beta3

* TestCase for the issue (using Twig's test models)
@Test
public void testIssue41 {
  // ObjectDatastore ods = ...
  try {
    ods.find().type().
    addFilter("hair", FilterOperator.EQUAL, Band.HairStyle.LONG_LIKE_A_GIRL).
    now(); }
catch(IllegalArgumentException e) {
    fail("Issue41: Enum values not filtered correctly!");
  }
}

------ Stack trace (with same object types) -------

java.lang.IllegalArgumentException: gender: 
fi.turkuamk.examples.tests.LocalDatastoreTest$UserEntity$GenderEnum is not a 
supported property type.
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:184)
    at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:157)
    at com.google.appengine.api.datastore.Query$FilterPredicate.<init>(Query.java:549)
    at com.google.appengine.api.datastore.Query.addFilter(Query.java:235)
    at com.google.code.twig.standard.StandardCommonFindCommand.applyFilters(StandardCommonFindCommand.java:141)
    at com.google.code.twig.standard.StandardRootFindCommand.newQuery(StandardRootFindCommand.java:525)
    at com.google.code.twig.standard.StandardCommonFindCommand.queries(StandardCommonFindCommand.java:112)
    at com.google.code.twig.standard.StandardCommonFindCommand.getValidatedQueries(StandardCommonFindCommand.java:127)
    at com.google.code.twig.standard.StandardRootFindCommand.now(StandardRootFindCommand.java:454)
    at com.google.code.twig.standard.StandardRootFindCommand.now(StandardRootFindCommand.java:30)
    at fi.turkuamk.examples.tests.LocalDatastoreTest.testEnumFilterException(LocalDatastoreTest.java:332)
    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 24 Oct 2010 at 12:34

GoogleCodeExporter commented 8 years ago
ods.find().type() -> ods.find().type(RockBand.class)

Original comment by tero.nur...@gmail.com on 24 Oct 2010 at 12:36

GoogleCodeExporter commented 8 years ago
The solution should use the same property translator that originally encoded 
the field value.  This should also work for referenced instances.  The 
translator must return only a single "native" value or an exception should be 
thrown.

Original comment by jdpatterson on 24 Oct 2010 at 2:51

GoogleCodeExporter commented 8 years ago
There's a notion in Wiki for this bug: 
http://code.google.com/p/twig-persist/wiki/Using#Multiple_Query_Commands

Original comment by tero.nur...@gmail.com on 24 Oct 2010 at 8:30

GoogleCodeExporter commented 8 years ago
Ah good spotting!  It really is natural to use such values in filters.

Original comment by jdpatterson on 25 Oct 2010 at 2:47

GoogleCodeExporter commented 8 years ago
Fixed in the latest commit to v2.0

Original comment by jdpatterson on 25 Oct 2010 at 5:59