Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6361113

SQLDataSetSyncException after 2nd time DataSet.sync called. The new data exist in the data source.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 6
    • core-libs
    • generic
    • generic

      When DataSet.sync call for the 2nd time, it throws a SQLDataSetSyncException and at the same time, the Data Source is updated.

      0) Query data. (disconneted mode)
      1) insert a row with dup. key.
      2) DataSet.sync ---> have SQLDataSetSyncException as expected.
      3) Fix the conflited row. (make it same as DataSouce)
      4) DataSetResolver.sync.
      5) change the row with dup. key to a non-dup key then insert.
      6) DataSet.sync ---> It is given a SQLDataSetSyncException.
      7) Query the Data Source. ---> It has the new row added into the DataSouce.

      The question is why the Data Source has the new row when there is a SQLDataSetSyncException on 2nd time DataSet.sync?

      Should there be SQLDataSetSyncException when the DataSet has changed to a correct data?


      JDK : 1.6.0 b63
      DB : ORCL
      VM : default
      switch/Mode : default
      Platform[s] : Sol 9 and 10 sparc and x86

      Test owner :
      Failing Test :
          java_sql_eod/dataset/DataSet008_004

      TestBase Location:
      ==================

          /net/cady.sfbay/export/sqa/tcheung/jdbc/SQE/6.0

      Test source location:
      =====================
          /net/cady.sfbay/export/sqa/tcheung/jdbc/SQE/6.0/jdbc/src/java_sql_eod/dataset/DataSet008_004/*.java

      Share source location:
      ======================
         /net/cady/export/sqa/tcheung/jdbc/SQE/6.0/jdbc/share
         /net/cady/export/sqa/tcheung/jdbc/SQE/6.0/share

      sample file location:
      ==================
      /net/cady.sfbay/export/sqa/tcheung/jdbc/BUGS/[bug id]

      How to reproduce:
      ====================
      change the db ip,username and passwd.
      javac jdbc4_try.java
      java jdbc4_try
       

      --------Sample Test/Script START---------------------

      import java.sql.*;
      import javax.sql.*;

      interface myname extends BaseQuery {
        @Select(sql="select * from t",connected=false,tableName="t",readOnly=false )
        DataSet<t_class> getAll() throws SQLRuntimeException;
      }

      public class jdbc4_try
      {
      public static void main(String [] args) {

       Connection con = null;
       Statement s;
       String driverClassName = "com.inet.ora.OraDriver";
       DataSet<t_class> newCust = null;
       DataSet<t_class> newCust_2 = null;
       ConflictingRow confRow;
       
       t_class newRow = new t_class();
       
       try {
           Class.forName(driverClassName);
           con = DriverManager.getConnection("jdbc:inetora:ip:1521:ORCL","user","pass");
             myname myQImpl = null;
             s = con.createStatement();
             try {
             s.executeUpdate("DROP TABLE t"); }catch (Exception ex) {
               System.out.println("e1 "+ ex); }
             s.executeUpdate("CREATE TABLE t (age INT primary key, name VARCHAR2(50))");
             s.executeUpdate("INSERT INTO t values(10, 'custom1')");
             s.executeUpdate("INSERT INTO t values(22, 'custom2')");
             s.executeUpdate("INSERT INTO t values(33, 'testName')");

             ResultSet result = s.executeQuery("SELECT * from t");
             System.out.println("***ResultSet of 1st row***");
             result.next();
             System.out.println("custome is " + result.getString("name"));
             System.out.println("age is " + result.getString("age"));
             try {
                myQImpl = QueryObjectFactory.createDefaultQueryObject(myname.class,con);
             } catch (SQLException ex) {
                System.out.println("SQLException ");
             }
             try{
                 System.out.println("***1st DataSet output***");
                 newCust = myQImpl.getAll();
                 for (t_class c: newCust){
                     System.out.println("id " + c.age);
                     System.out.println("name " + c.name);
                 }
                 System.out.println("***Adding data: Age = 10 into 1st DataSet***");
                 newRow.age = 10;
                 newRow.name = "newRow";
                 newCust.insert(newRow);
                 
                 
             } catch (SQLRuntimeException rt)
             {
                 System.out.println("SQLException ");
             }
           
             try{
                 newCust.sync();
             }catch(SQLDataSetSyncException sql_ds_se)
             {
                 System.out.println("SQLDataSetSyncException ");
                 
                 DataSetResolver<ConflictingRow> ds = sql_ds_se.getDataSetResolver();

                 
                 for (ConflictingRow row : ds) {
                     System.out.println("Setting the data back the way it was.");
                     
                     
                     t_class EnewRow = (t_class) row.getRow();
                     
                     System.out.println("newRow " + EnewRow.age);
                     EnewRow.age = 10;
                     EnewRow.name= "player1_fName";
                       
                 }
                 System.out.println("DataSetResolver.sync called");
                 ds.sync();
                 
                 
             }
             try{
                 newCust_2 = myQImpl.getAll();
                 System.out.println("*** Query Database using a new DataSet ***");
                 for (t_class c: newCust_2){
                     System.out.println("id " + c.age);
                     System.out.println("name " + c.name);
                 }
             } catch (SQLRuntimeException rt)
             {
                 System.out.println("SQLException ");
             }
             //newCust.clearWarnings();
             newRow.age = 100;
             System.out.println("***change the 1st DataSet age to " + newRow.age + " ***");
             newCust.insert(newRow);
             try{
                 newCust.sync();
             }catch(SQLDataSetSyncException sql_ds_se)
             {
                 System.out.println("SQLDataSetSyncException Again");
                 
             }
             
             try{
                 newCust = myQImpl.getAll();
                 System.out.println("*** Query again of 1st DataSet ***");
                 for (t_class c: newCust){
                     System.out.println("id " + c.age);
                     System.out.println("name " + c.name);
                 }
             } catch (SQLRuntimeException rt)
             {
                 System.out.println("SQLException ");
             }
             
       }catch(Exception ex) { System.out.println("2 exception." + ex); ex.printStackTrace(); }
      }
      }

      public class t_class {
        int age;
        String name;
      }


      --------Sample Test/Script END----------------------

      Test output:
      =============
      ***ResultSet of 1st row***
      custome is custom1
      age is 10
      ***1st DataSet output***
      id 10
      name custom1
      id 22
      name custom2
      id 33
      name testName
      ***Adding data: Age = 10 into 1st DataSet***
      SQLDataSetSyncException
      Setting the data back the way it was.
      newRow 10
      DataSetResolver.sync called
      *** Query Database using a new DataSet ***
      id 10
      name custom1
      id 22
      name custom2
      id 33
      name testName
      ***change the 1st DataSet age to 100 ***
      SQLDataSetSyncException Again
      *** Query again of 1st DataSet ***
      id 10
      name custom1
      id 22
      name custom2
      id 33
      name testName
      id 100
      name newRow


      Specific Machine Info:
      =====================
      For Solaris[sparc/x86] ->
      SunOS orthello 5.10 Generic sun4u sparc SUNW,Ultra-60

            ssharmasunw Sushmita Sharma (Inactive)
            tacheung Tak Wing Cheung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: