Using Smart GWT 3.0 nightlies.
I believe there is a bug in the asAdvancedCriteria method logic on the Criteria class.
Steps to reproduce:
1) Create a standard Criteria object.
2) Add to it a single Criteria of "id" with an array of Doubles
3) Convert the Criteria object to an AdvancedCriteria object using the asAdvancedCriteria() method
4) Note how the new advancedCriteria contains a list of criterions joined by OR, but that each individual criterion is using 'iContains'
5) Try to fetch data with desired criteria and notice how the array originally contained [1, 2], BUT records with 'id' 1, 2, 11, 12, 21, 22, 31, 32, etc. are returned b/c of the iContains operator. Believe this operator should instead by EQUALS or a list should be created in the AdvancedCriteria object and IN_SET operator should be used. Note how the conversion method knows to keep the value as a number, not a string which is good, but the iContains throws everything off.
Example follows:
Output:
Here's the request and response of my actual data fetch. Note that I am passing 2 and 3 to the criteria object for field 'device_id'. I have some additional criteria too but that's working.
Request (see iContains operator for two List objects in the criteria section)
Response (should only be returning objects with device_id =2 and device_id = 3 but notice how any object that has a 2 or 3 in its device_id is returned):
I believe there is a bug in the asAdvancedCriteria method logic on the Criteria class.
Steps to reproduce:
1) Create a standard Criteria object.
2) Add to it a single Criteria of "id" with an array of Doubles
3) Convert the Criteria object to an AdvancedCriteria object using the asAdvancedCriteria() method
4) Note how the new advancedCriteria contains a list of criterions joined by OR, but that each individual criterion is using 'iContains'
5) Try to fetch data with desired criteria and notice how the array originally contained [1, 2], BUT records with 'id' 1, 2, 11, 12, 21, 22, 31, 32, etc. are returned b/c of the iContains operator. Believe this operator should instead by EQUALS or a list should be created in the AdvancedCriteria object and IN_SET operator should be used. Note how the conversion method knows to keep the value as a number, not a string which is good, but the iContains throws everything off.
Example follows:
Code:
Criteria crit = new Criteria(); crit.addCriteria("id", new Double[] { new Double(1), new Double(2) }); System.out.println(JSON.encode(crit.getJsObj())); AdvancedCriteria advCrit = crit.asAdvancedCriteria(); System.out.println(JSON.encode(advCrit.getJsObj()));
Code:
{ "__gwt_ObjectId":4244, "id":[ 1, 2 ] } { "_constructor":"AdvancedCriteria", "operator":"and", "criteria":[ { "fieldName":"__gwt_ObjectId", "operator":"equals", "value":4244 }, { "_constructor":"AdvancedCriteria", "operator":"or", "criteria":[ { "fieldName":"id", "operator":"iContains", "value":1 }, { "fieldName":"id", "operator":"iContains", "value":2 } ] } ], "__gwt_ObjectId":4246 }
Request (see iContains operator for two List objects in the criteria section)
Code:
<transaction xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:type="xsd:Object"> <transactionNum xsi:type="xsd:long">13</transactionNum> <operations xsi:type="xsd:List"> <elem xsi:type="xsd:Object"> <criteria xsi:type="xsd:Object"> <_constructor>AdvancedCriteria</_constructor> <operator>and</operator> <criteria xsi:type="xsd:List"> <elem xsi:type="xsd:Object"> <fieldName>__gwt_ObjectId</fieldName> <operator>equals</operator> <value xsi:type="xsd:long">6544</value> </elem> <elem xsi:type="xsd:Object"> <_constructor>AdvancedCriteria</_constructor> <operator>or</operator> <criteria xsi:type="xsd:List"> <elem xsi:type="xsd:Object"> <fieldName>device_id</fieldName> <operator>iContains</operator> <value xsi:type="xsd:long">2</value> </elem> <elem xsi:type="xsd:Object"> <fieldName>device_id</fieldName> <operator>iContains</operator> <value xsi:type="xsd:long">3</value> </elem> </criteria> </elem> <elem xsi:type="xsd:Object"></elem> <elem xsi:type="xsd:Object"> <fieldName>ospf_id</fieldName> <operator>notNull</operator> <value xsi:type="xsd:boolean">true</value> </elem> </criteria> <__gwt_ObjectId xsi:type="xsd:long">6546</__gwt_ObjectId> </criteria> <operationConfig xsi:type="xsd:Object"> <dataSource>routing_network</dataSource> <operationType>fetch</operationType> <textMatchStyle>exact</textMatchStyle> </operationConfig> <startRow xsi:type="xsd:long">0</startRow> <endRow xsi:type="xsd:long">50</endRow> <componentId>isc_ListGrid_16</componentId> <appID>builtinApplication</appID> <operation>routing_network_fetch</operation> <oldValues xsi:type="xsd:Object"> <_constructor>AdvancedCriteria</_constructor> <operator>and</operator> <criteria xsi:type="xsd:List"> <elem xsi:type="xsd:Object"> <fieldName>__gwt_ObjectId</fieldName> <operator>equals</operator> <value xsi:type="xsd:long">6544</value> </elem> <elem xsi:type="xsd:Object"> <_constructor>AdvancedCriteria</_constructor> <operator>or</operator> <criteria xsi:type="xsd:List"> <elem xsi:type="xsd:Object"> <fieldName>device_id</fieldName> <operator>iContains</operator> <value xsi:type="xsd:long">2</value> </elem> <elem xsi:type="xsd:Object"> <fieldName>device_id</fieldName> <operator>iContains</operator> <value xsi:type="xsd:long">3</value> </elem> </criteria> </elem> <elem xsi:type="xsd:Object"></elem> <elem xsi:type="xsd:Object"> <fieldName>ospf_id</fieldName> <operator>notNull</operator> <value xsi:type="xsd:boolean">true</value> </elem> </criteria> <__gwt_ObjectId xsi:type="xsd:long">6546</__gwt_ObjectId> </oldValues> </elem> </operations> </transaction>
Code:
[ { data : [ { id : 6, area : 1, wildcard : "0.0.0.3", lineStart : 234, ospf_id : 4, hostName : "bills_PE_12406_01", device_id : 2 }, { id : 7, area : 1, wildcard : "0.0.0.3", lineStart : 393, ospf_id : 7, hostName : "bills_PE_12406_02", device_id : 3 }, { id : 29, area : 1, wildcard : "0.0.0.3", lineStart : 400, ospf_id : 30, hostName : "jets_PE_12406_01", device_id : 12 }, { id : 42, area : 1, wildcard : "0.0.0.3", lineStart : 356, ospf_id : 37, hostName : "jets_PE_12406_02", device_id : 13 }, { id : 64, area : 1, wildcard : "0.0.0.3", lineStart : 374, ospf_id : 54, hostName : "packers_PE_12406_02", device_id : 20 }, { . . .
Comment