Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Bug in serverside DSRequest.addToCriteria(AdvancedCriteria ac)

    Hi Isomorphic,

    please see the following in changed builtInDS example (SNAPSHOT_v9.1d_2014-01-25):
    animals.ds.xml
    Code:
    <serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.Animals" />
    Animals.java
    Code:
    package com.smartgwt.sample.server.listener;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.isomorphic.criteria.AdvancedCriteria;
    import com.isomorphic.criteria.Criterion;
    import com.isomorphic.criteria.DefaultOperators;
    import com.isomorphic.criteria.criterion.IsNullCriterion;
    import com.isomorphic.criteria.criterion.SimpleCriterion;
    import com.isomorphic.datasource.DSRequest;
    import com.isomorphic.datasource.DSResponse;
    
    public class Animals {
    	public DSResponse fetch(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
    		AdvancedCriteria ac = new AdvancedCriteria(DefaultOperators.Or, new Criterion[] {
    				new SimpleCriterion("lifeSpan", DefaultOperators.Equals, 20), new IsNullCriterion("status") });
    		dsRequest.addToCriteria(ac);
    		return dsRequest.execute();
    	}
    }
    ac is a valid AdvancedCriteria.
    But if you watch in Eclipse DevMode debug mode, "Expressions": dsRequest.getAdvancedCriteria() -> Criteria -> mCriteria -> elementData -> [0] you'll see that it is null.

    This might be related to my older (client side) bug report http://forums.smartclient.com/showthread.php?t=28401.

    My stack trace in the sample is:
    Code:
    === 2014-01-26 13:12:34,089 [2-33] DEBUG DataSourceDMI - Invocation threw exception
    java.lang.NullPointerException
    	at com.isomorphic.datasource.IncludeFromDefinition.isDynamicInclusion(IncludeFromDefinition.java:117)
    	at com.isomorphic.datasource.DSRequest.buildIncludeFromDefinitions(DSRequest.java:4660)
    	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2400)
    	at com.smartgwt.sample.server.listener.Animals.fetch(Animals.java:18)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:975)
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:416)
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
    	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2561)
    ......
    In my app, the trace is:
    Code:
    	at com.isomorphic.datasource.IncludeFromDefinition.forField(IncludeFromDefinition.java:154)
    	at com.isomorphic.datasource.IncludeFromDefinition.forCriteriaField(IncludeFromDefinition.java:134)
    	at com.isomorphic.datasource.DSRequest.mapRawCriteriaFieldNames(DSRequest.java:5562)
    	at com.isomorphic.datasource.DSRequest.getNonSqlCriteriaFields(DSRequest.java:5368)
    	at com.isomorphic.datasource.DSRequest.hasNonSqlCriteria(DSRequest.java:5357)
    	at com.isomorphic.sql.SQLWhereClause.getOutput(SQLWhereClause.java:328)
    	at com.isomorphic.sql.SQLWhereClause.toString(SQLWhereClause.java:309)
    	at com.isomorphic.sql.SQLWhereClause.getSQLString(SQLWhereClause.java:315)
    	at com.isomorphic.sql.SQLDataSource.getClausesContext(SQLDataSource.java:2996)
    	at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1682)
    	at com.isomorphic.sql.SQLDataSource.processRequest(SQLDataSource.java:411)
    	at com.isomorphic.sql.SQLDataSource.executeFetch(SQLDataSource.java:356)
    ......

    Best regards,
    Blama

    #2
    We just committed a fix for this problem on the 9.1 branch. Please try your use case with tomorrow's build and let us know how it goes.

    Thanks
    Isomorphic Support

    Comment


      #3
      Hi Isomorphic,

      your change fixed that problem in my use case but opened a new one (regression?). See this example:

      Animals.java (ServerObject from above)
      Code:
      package com.smartgwt.sample.server.listener;
      
      import java.util.HashSet;
      
      import javax.servlet.http.HttpServletRequest;
      
      import com.isomorphic.criteria.AdvancedCriteria;
      import com.isomorphic.criteria.Criterion;
      import com.isomorphic.criteria.DefaultOperators;
      import com.isomorphic.datasource.DSRequest;
      import com.isomorphic.datasource.DSResponse;
      
      public class Animals {
      	public DSResponse fetch(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
      		// 1st)
      		HashSet<Long> set = new HashSet<Long>();
      		set.add(new Long(10L));
      		set.add(new Long(20L));
      		set.add(new Long(30L));
      		set.add(new Long(50L));
      		dsRequest.addToCriteria("lifeSpan", DefaultOperators.InSet.getID(), set);
      		// 2st)
      		dsRequest.addToCriteria("status", DefaultOperators.Equals, "Threatened");
      
      		// Un-comment this to "repair".
      //		dsRequest.setAdvancedCriteria(new AdvancedCriteria(DefaultOperators.And, new Criterion[] { dsRequest
      //				.getAdvancedCriteria().asCriterion() }));
      		return dsRequest.execute();
      	}
      }
      The SetCriterion looks good in the debugger watch expressions, but is evaluated to ('0'='1'). The setAdvancedCriteria(getAdvancedCriteria()) really helps here!

      Best regards,
      Blama

      Comment


        #4
        Thanks for the report - we have now fixed this. Note, this was not a breakage or regression - it has never worked. If you think you have seen an "inSet" criterion added via the addToCriteria() API and handled correctly, chances are that you were passing a List rather than a Set.

        Anyway, the fix will be in tomorrow's build, (January 30)

        Comment


          #5
          Hi Isomorphic,

          you are correct. I switched from ArrayList<Long> to HashSet<Long> after realizing that a Set-implementation is more logical in this case.

          Thanks for fixing, I'll test with tomorrow's build and let you know.

          Best regards,
          Blama

          Comment


            #6
            Hi Isomorphic,

            it works as expected in my use case.

            Thank you & best regards,
            Blama

            Comment

            Working...
            X