Announcement

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

    Bug with setValues overwriting DS-Criteria in DMI

    Hi Isomorphic,

    I have a per-operationType DMI (acting on update), that does issue following additional request:
    Code:
    DSRequest secondUpdateRequest = new DSRequest(dsRequest.getDataSource().getID(), "update");
    secondUpdateRequest.setOperationId("updateHauptadresse");
    secondUpdateRequest.setRPCManager(dsRequest.getRPCManager());
    secondUpdateRequest.setValues(new HashMap<String, String>() {
    				{
    					put("HAUPTADRESSE", "N");
    				}
    			});
    DSResponse secondUpdateResponse = secondUpdateRequest.execute();
    The OperationBinding is as follows:
    Code:
    <operationBinding operationType="update" operationId="updateHauptadresse" allowMultiUpdate="true">
    	<criteria fieldName="HAUPTADRESSE" value="J" />
    	<values fieldName="MODIFIED_BY" value="1" />
    	<values fieldName="MODIFIED_AT" value="$currentDate" />
    </operationBinding>
    The generated SQL is:
    Code:
    === 2012-04-18 12:14:30,378 [l0-6] DEBUG AppBase - [builtinApplication.updateHauptadresse] No userTypes defined, allowing anyone access to all operations for this application
    === 2012-04-18 12:14:30,379 [l0-6] DEBUG AppBase - [builtinApplication.updateHauptadresse] No public zero-argument method named '_updateHauptadresse' found, performing generic datasource operation
    === 2012-04-18 12:14:30,384 [l0-6] INFO  SQLDataSource - [builtinApplication.updateHauptadresse] Performing update operation with
    	criteria: {HAUPTADRESSE:"J"}	values: {MODIFIED_AT:new Date(1334744070372),MODIFIED_BY:1,HAUPTADRESSE:false}
    === 2012-04-18 12:14:30,389 [l0-6] INFO  SQLDriver - [builtinApplication.updateHauptadresse] Executing SQL update on 'Oracle': UPDATE T_ANSCHRIFT SET HAUPTADRESSE='N', MODIFIED_AT=TO_DATE('2012-04-18 12:14:30','YYYY-MM-DD HH24:MI:SS'), MODIFIED_BY=1 WHERE (T_ANSCHRIFT.HAUPTADRESSE='N')
    === 2012-04-18 12:14:30,392 [l0-6] DEBUG SQLDataSource - [builtinApplication.updateHauptadresse] update operation affected 2 rows
    See how the WHERE-clause of the generated SQL is 'N' and not 'J' as expected from the ds.xml criteria.
    Also setting the criteria in the code does not solve this. Once set, setValues overwrites them. For me, this seems to be a bug.

    Best regards,
    Blama

    #2
    Can you reproduce this by adding code to a sample? (so that we know it's not caused by additional code you haven't shown).

    Comment


      #3
      Hi Isomorphic,

      see attached sample, added to built-in-ds:
      .sql (Oracle):
      Code:
      DROP TABLE t_test CASCADE CONSTRAINTS 
      ;
      
      DROP SEQUENCE T_TEST_ID
      ;
      CREATE TABLE t_test 
          ( 
           id INTEGER  NOT NULL , 
           once_y VARCHAR2 (1 CHAR)  NOT NULL CHECK ( once_y IN ('N', 'Y')) , 
           foo VARCHAR2 (100 CHAR) , 
           bar VARCHAR2 (100 CHAR) , 
           modified_by INTEGER  NOT NULL , 
           modified_at DATE DEFAULT SYSDATE  NOT NULL 
          ) 
      ;
      
      ALTER TABLE t_test 
          ADD CONSTRAINT PK_test PRIMARY KEY ( id ) ;
      
      CREATE SEQUENCE T_TEST_ID 
          NOCACHE 
          ORDER ;
      
      CREATE OR REPLACE TRIGGER t_test_BI 
      BEFORE INSERT ON t_test 
      FOR EACH ROW 
      WHEN (NEW.id IS NULL) 
      BEGIN 
          SELECT T_TEST_ID.NEXTVAL INTO :NEW.id FROM DUAL; 
      END;
      /
      
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('N', 1);
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('N', 1);
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('N', 1);
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('N', 1);
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('N', 1);
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('N', 1);
      INSERT INTO T_TEST(once_y, modified_by) VALUES ('Y', 1);
      COMMIT;
      Testcase.java:
      Code:
      package com.smartgwt.sample.client;
      
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.widgets.IButton;
      import com.smartgwt.client.widgets.events.ClickEvent;
      import com.smartgwt.client.widgets.events.ClickHandler;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.layout.VLayout;
      import com.google.gwt.core.client.EntryPoint;
      
      public class Testcase implements EntryPoint {
      	@Override
      	public void onModuleLoad() {
      
      		VLayout vL = new VLayout() {
      			{
      				setWidth100();
      				setHeight100();
      				final DataSource testDS = DataSource.get("T_TEST");
      
      				final ListGrid testLG = new ListGrid() {
      					{
      						setDataSource(testDS);
      						fetchData();
      						setCanEdit(true);
      					}
      				};
      				
      				final IButton btn = new IButton("Reload", new ClickHandler() {
      					@Override
      					public void onClick(ClickEvent event) {
      						testDS.invalidateCache();
      						testLG.fetchData();
      					}
      				});
      				setMembersMargin(10);
      				addMember(testLG);
      				addMember(btn);
      			}
      		};
      		vL.draw();
      	}
      }
      UpdateYtoN.java Server:
      Code:
      package com.smartgwt.sample.server;
      
      import java.math.BigDecimal;
      import java.util.HashMap;
      import com.isomorphic.criteria.AdvancedCriteria;
      import com.isomorphic.criteria.DefaultOperators;
      import com.isomorphic.datasource.DSRequest;
      import com.isomorphic.datasource.DSResponse;
      import com.isomorphic.sql.SQLTransaction;
      import com.isomorphic.criteria.Criterion;
      import com.isomorphic.criteria.criterion.SimpleCriterion;
      import javax.servlet.http.HttpServletRequest;
      
      public class UpdateYtoN {
      
      	@SuppressWarnings("serial")
      	public DSResponse updateYtoN(DSRequest dsRequest, HttpServletRequest servletRequest)
      			throws Exception {
      		if (dsRequest.getFieldValue("ONCE_Y") == null
      				|| ((Boolean) dsRequest.getFieldValue("ONCE_Y")) == false)
      			return dsRequest.execute();
      		else {
      			SQLTransaction.startTransaction(dsRequest.getRPCManager());
      			DSResponse firstUpdateResponse = dsRequest.execute();
      
      			DSRequest secondUpdateRequest = new DSRequest(dsRequest.getDataSource().getID(), "update");
      			secondUpdateRequest.setOperationId("updateYtoN");
      
      			SimpleCriterion notID = new SimpleCriterion("ID", "notEqual", (BigDecimal) firstUpdateResponse
      					.getDataField("ID"));
      
      			SimpleCriterion isY = new SimpleCriterion("ONCE_Y", "equals", "Y");
      
      			// Alle anderen zurück setzen.
      			AdvancedCriteria notIDAndIsY = new AdvancedCriteria(DefaultOperators.And,
      					new Criterion[] { isY, notID });
      			secondUpdateRequest.setRPCManager(dsRequest.getRPCManager());
      			secondUpdateRequest.setValues(new HashMap<String, String>() {
      				{
      					put("ONCE_Y", "N");
      				}
      			});
      			secondUpdateRequest.setAdvancedCriteria(notIDAndIsY);
      			DSResponse secondUpdateResponse = secondUpdateRequest.execute();
      			if (firstUpdateResponse.getStatus() == DSResponse.STATUS_SUCCESS
      					&& firstUpdateResponse.getAffectedRows() == 1
      					&& secondUpdateResponse.getStatus() == DSResponse.STATUS_SUCCESS) {
      				SQLTransaction.commitTransaction(dsRequest.getRPCManager());
      
      				//Zeilen zurück gesetzt, jetzt dies noch dem Client mitteilen.
      				DSRequest selectRequest = new DSRequest(dsRequest.getDataSource().getID(), "fetch");
      				selectRequest.setCriteria("ONCE_Y", "N");
      				DSResponse selectResponse = selectRequest.execute();
      				SQLTransaction.endTransaction(dsRequest.getRPCManager());
      				return firstUpdateResponse.addRelatedUpdate(selectResponse);
      			} else {
      				SQLTransaction.rollbackTransaction(dsRequest.getRPCManager());
      				SQLTransaction.endTransaction(dsRequest.getRPCManager());
      				return new DSResponse(DSResponse.STATUS_FAILURE);
      			}
      		}
      	}
      };
      T_TEST.ds.xml:
      Code:
      <DataSource schema="TEST" dbName="Oracle" tableName="T_TEST" ID="T_TEST" dataSourceVersion="1"
      	serverType="sql"
      >
      	<fields>
      		<field primaryKey="true" name="ID" type="sequence"></field>
      		<field name="ONCE_Y" title="Once Y" length="1" type="boolean" sqlStorageStrategy="singleChar" sqlTrueValue="Y"
      			sqlFalseValue="N" required="true" />
      		<field name="FOO" length="100" type="text"></field>
      		<field name="BAR" length="100" type="text"></field>
      		<field name="MODIFIED_BY" required="true" hidden="true" type="int"></field>
      		<field name="MODIFIED_AT" type="datetime" title="Geändert"></field>
      	</fields>
      	<operationBindings>
      		<operationBinding operationType="add">
      			<values fieldName="MODIFIED_BY" value="1" />
      			<values fieldName="MODIFIED_AT" value="$currentDate" />
      		</operationBinding>
      		<operationBinding operationType="update">
      			<serverObject lookupStyle="new" className="com.smartgwt.sample.server.UpdateYtoN"
      				methodName="updateYtoN" />
      			<values fieldName="MODIFIED_BY" value="1" />
      			<values fieldName="MODIFIED_AT" value="$currentDate" />
      		</operationBinding>
      		<operationBinding operationType="update" operationId="updateYtoN" allowMultiUpdate="true">
      			<values fieldName="MODIFIED_BY" value="1" />
      			<values fieldName="MODIFIED_AT" value="$currentDate" />
      		</operationBinding>
      	</operationBindings>
      </DataSource>
      Serverlog for N->Y:
      Code:
      === 2012-04-19 11:26:15,955 [0-13] INFO  RequestContext - URL: '/builtinds/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0': Moz (Gecko) with Accept-Encoding header
      === 2012-04-19 11:26:15,972 [0-13] DEBUG XML - Parsed XML from (in memory stream): 16ms
      === 2012-04-19 11:26:15,975 [0-13] DEBUG RPCManager - Processing 1 requests.
      === 2012-04-19 11:26:15,976 [0-13] DEBUG RPCManager - Request #1 (DSRequest) payload: {
          criteria:{
              ID:4
          },
          values:{
              ID:4,
              ONCE_Y:true
          },
          operationConfig:{
              dataSource:"T_TEST",
              operationType:"update"
          },
          componentId:"isc_Testcase_1$1_0",
          appID:"builtinApplication",
          operation:"T_TEST_update",
          oldValues:{
              MODIFIED_AT:new Date(1334827056000),
              ID:4,
              ONCE_Y:false,
              MODIFIED_BY:1
          }
      }
      === 2012-04-19 11:26:15,976 [0-13] INFO  IDACall - Performing 1 operation(s)
      === 2012-04-19 11:26:15,989 [0-13] DEBUG PoolableSQLConnectionFactory - Returning pooled Connection
      === 2012-04-19 11:26:15,990 [0-13] DEBUG SQLTransaction - Started new Oracle transaction "1167679797"
      === 2012-04-19 11:26:15,990 [0-13] DEBUG AppBase - [builtinApplication.T_TEST_update] No userTypes defined, allowing anyone access to all operations for this application
      === 2012-04-19 11:26:15,990 [0-13] DEBUG AppBase - [builtinApplication.T_TEST_update] No public zero-argument method named '_T_TEST_update' found, performing generic datasource operation
      === 2012-04-19 11:26:15,990 [0-13] INFO  SQLDataSource - [builtinApplication.T_TEST_update] Performing update operation with
      	criteria: {ID:4}	values: {ID:4,ONCE_Y:true,MODIFIED_BY:1,MODIFIED_AT:new Date(1334827575976)}
      === 2012-04-19 11:26:15,991 [0-13] INFO  SQLDriver - [builtinApplication.T_TEST_update] Executing SQL update on 'Oracle': UPDATE TEST.T_TEST SET MODIFIED_AT=TO_DATE('2012-04-19 11:26:15','YYYY-MM-DD HH24:MI:SS'), MODIFIED_BY=1, ONCE_Y='Y' WHERE (T_TEST.ID='4')
      === 2012-04-19 11:26:15,992 [0-13] DEBUG SQLDataSource - [builtinApplication.T_TEST_update] update operation affected 1 rows
      === 2012-04-19 11:26:15,992 [0-13] INFO  SQLDataSource - [builtinApplication.T_TEST_update] primaryKeys: {ID=4}
      === 2012-04-19 11:26:15,993 [0-13] DEBUG AppBase - [builtinApplication.T_TEST_update, builtinApplication.null] No userTypes defined, allowing anyone access to all operations for this application
      === 2012-04-19 11:26:15,993 [0-13] DEBUG AppBase - [builtinApplication.T_TEST_update, builtinApplication.null] No public zero-argument method named '_null' found, performing generic datasource operation
      === 2012-04-19 11:26:15,993 [0-13] INFO  SQLDataSource - [builtinApplication.T_TEST_update, builtinApplication.null] Performing fetch operation with
      	criteria: {ID:4}	values: {ID:4}
      === 2012-04-19 11:26:15,993 [0-13] INFO  SQLDataSource - [builtinApplication.T_TEST_update, builtinApplication.null] derived query: SELECT $defaultSelectClause FROM $defaultTableClause WHERE $defaultWhereClause
      === 2012-04-19 11:26:15,994 [0-13] INFO  SQLDataSource - [builtinApplication.T_TEST_update, builtinApplication.null] Executing SQL query on 'Oracle': SELECT T_TEST.BAR, T_TEST.FOO, T_TEST.ID, T_TEST.MODIFIED_AT, T_TEST.MODIFIED_BY, T_TEST.ONCE_Y FROM TEST.T_TEST WHERE (T_TEST.ID='4')
      === 2012-04-19 11:26:15,994 [0-13] INFO  SQLDriver - [builtinApplication.T_TEST_update, builtinApplication.null] Executing SQL query on 'Oracle': SELECT T_TEST.BAR, T_TEST.FOO, T_TEST.ID, T_TEST.MODIFIED_AT, T_TEST.MODIFIED_BY, T_TEST.ONCE_Y FROM TEST.T_TEST WHERE (T_TEST.ID='4')
      === 2012-04-19 11:26:15,997 [0-13] INFO  DSResponse - [builtinApplication.T_TEST_update, builtinApplication.null] DSResponse: List with 1 items
      === 2012-04-19 11:26:15,997 [0-13] INFO  DSResponse - [builtinApplication.T_TEST_update] DSResponse: List with 1 items
      === 2012-04-19 11:26:15,998 [0-13] DEBUG AppBase - [builtinApplication.updateYtoN] No userTypes defined, allowing anyone access to all operations for this application
      === 2012-04-19 11:26:15,998 [0-13] DEBUG AppBase - [builtinApplication.updateYtoN] No public zero-argument method named '_updateYtoN' found, performing generic datasource operation
      === 2012-04-19 11:26:15,999 [0-13] INFO  SQLDataSource - [builtinApplication.updateYtoN] Performing update operation with
      	criteria: {criteria:[{value:"Y",fieldName:"ONCE_Y",operator:"equals"},{value:4,fieldName:"ID",operator:"notEqual"}],operator:"and",_constructor:"AdvancedCriteria"}	values: {MODIFIED_AT:new Date(1334827575998),ONCE_Y:false,MODIFIED_BY:1}
      === 2012-04-19 11:26:15,999 [0-13] INFO  SQLDriver - [builtinApplication.updateYtoN] Executing SQL update on 'Oracle': UPDATE TEST.T_TEST SET MODIFIED_AT=TO_DATE('2012-04-19 11:26:15','YYYY-MM-DD HH24:MI:SS'), MODIFIED_BY=1, ONCE_Y='N' WHERE ((T_TEST.ONCE_Y = 'N' AND T_TEST.ONCE_Y IS NOT NULL) AND (T_TEST.ID <> '4' OR T_TEST.ID IS NULL))
      === 2012-04-19 11:26:16,002 [0-13] DEBUG SQLDataSource - [builtinApplication.updateYtoN] update operation affected 3 rows
      === 2012-04-19 11:26:16,002 [0-13] DEBUG SQLTransaction - Committing Oracle transaction "1167679797"
      === 2012-04-19 11:26:16,003 [0-13] DEBUG AppBase - [builtinApplication.null] No userTypes defined, allowing anyone access to all operations for this application
      === 2012-04-19 11:26:16,003 [0-13] DEBUG AppBase - [builtinApplication.null] No public zero-argument method named '_null' found, performing generic datasource operation
      === 2012-04-19 11:26:16,003 [0-13] INFO  SQLDataSource - [builtinApplication.null] Performing fetch operation with
      	criteria: {ONCE_Y:"N"}	values: {ONCE_Y:"N"}
      === 2012-04-19 11:26:16,003 [0-13] INFO  SQLDataSource - [builtinApplication.null] derived query: SELECT $defaultSelectClause FROM $defaultTableClause WHERE $defaultWhereClause
      === 2012-04-19 11:26:16,004 [0-13] INFO  SQLDataSource - [builtinApplication.null] Executing SQL query on 'Oracle': SELECT T_TEST.BAR, T_TEST.FOO, T_TEST.ID, T_TEST.MODIFIED_AT, T_TEST.MODIFIED_BY, T_TEST.ONCE_Y FROM TEST.T_TEST WHERE (T_TEST.ONCE_Y='N')
      === 2012-04-19 11:26:16,015 [0-13] DEBUG PoolableSQLConnectionFactory - [builtinApplication.null] Returning pooled Connection
      === 2012-04-19 11:26:16,015 [0-13] INFO  SQLDriver - [builtinApplication.null] Executing SQL query on 'Oracle': SELECT T_TEST.BAR, T_TEST.FOO, T_TEST.ID, T_TEST.MODIFIED_AT, T_TEST.MODIFIED_BY, T_TEST.ONCE_Y FROM TEST.T_TEST WHERE (T_TEST.ONCE_Y='N')
      === 2012-04-19 11:26:16,016 [0-13] INFO  DSResponse - [builtinApplication.null] DSResponse: List with 3 items
      === 2012-04-19 11:26:16,017 [0-13] DEBUG SQLTransaction - Ending Oracle transaction "1167679797"
      === 2012-04-19 11:26:16,018 [0-13] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
      === 2012-04-19 11:26:16,018 [0-13] DEBUG RPCManager - DMI response, dropExtraFields: true
      === 2012-04-19 11:26:16,020 [0-13] INFO  Compression - /builtinds/sc/IDACall: 569 -> 272 bytes
      Best regards,
      Blama

      Comment


        #4
        Tested with SC_SNAPSHOT-2011-12-05/EVAL Deployment 2011-12-05 and v8.2p_2012-04-14/EVAL Deployment 2012-04-14.

        Comment

        Working...
        X