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

REGRESSION: DataSet with @Select & connected=true does not throw any exception when calling sync()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 6
    • 6
    • core-libs
    • b86
    • 6
    • b95
    • generic
    • generic
    • Verified

      JDK : Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
                       Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode)
      DB : Oracle 9i, DB2 8.1, SQL Server 2000
      Driver : Oracle/I-Net Oranxo.jar, DB2/DataDirect 3.5, SQL Server/I-Net Merlia.jar
      Platform[s] : All
      Testcases :

      java_sql_eod/dataset/DataSet002_001 compile_and_execute
      java_sql_eod/dataset/DataSet002_002 compile_and_execute
      java_sql_eod/dataset/DataSet002_003 compile_and_execute

      I presumed this was a test bug. Unfortunately that is not true. When using @Select annotation with connected=true, as per the documentation a call to sync() should not be allowed or throw a SQLRuntimeException. This was functioning correctly in build 85, but fails in build 86. Here is the output from build 85:

      ...
      check isConnected()=true
      dsmd.ownDeletesAreVisible(..)=false
      DataSet002_001.doTest() : Calling DataSet.sync()...
      DataSet002_001.doTest() : Caught SQLRuntimeException SQLException :Either a connection or a DataSource should be set on the DataSet for using his method
      DataSet002_001.doTest() : SQLException thrown when invoking DataSet.sync in connected Rowset . TEST PASSED
      Executing: delete from dataset002
      Executing: drop table dataset002

      [1674]sandeepk@scooter:~/workspace/6.0/jdbc/4.0_tests $ cat workDir/sandeepk.SunOS.sparc/DataSet002_001/DataSet002_001.err
      JDBCUtils.executeStmt : SQLException when executing statement. sql=delete from dataset002
      java.sql.SQLRuntimeException: Either a connection or a DataSource should be set on the DataSet for using his method
              at com.sun.sql.DataSetImpl.sync(DataSetImpl.java:1259)
              at DataSet002_001.doTest(DataSet002_001.java:122)
              at DataSet002_001.main(DataSet002_001.java:196)


      The output from build 86 is:

      ...
      check isConnected()=true
      dsmd.ownDeletesAreVisible(..)=false
      DataSet002_001.doTest() : Calling DataSet.sync()...
      No SQLRuntimeException thrown when invoking DataSet.sync() in connected Rowset : TEST FAILED
      Executing: delete from dataset002
      Executing: drop table dataset002

      [1669]sandeepk@scooter:~/workspace/6.0/jdbc/4.0_tests $ cat workDir/sandeepk.SunOS.sparc/DataSet002_001/DataSet002_001.err
      JDBCUtils.executeStmt : SQLException when executing statement. sql=delete from dataset002
      TEST FAILED : DataSet002_001.doTest() :No SQLException thrown when invoking DataSet.sync() in connected Rowset .
      com.sun.j2se_sqe.jdbc.utils.TestFailureException: No SQLException thrown when invoking DataSet.sync() in connected Rowset .
              at DataSet002_001.doTest(DataSet002_001.java:140)
              at DataSet002_001.main(DataSet002_001.java:196)

      Steps to reproduce:
      ===================

      Test source location: Any one of the three failing tests.
      =====================
      /net/cady/export/dtf/unified/knight-ws/suites/6.0/jdbc/src/java_sql_eod/dataset/DataSet002_001/DataSet002_001.java


      Testcase Description (DataSet002_001/2/3):
      =========================================
      Test executes a @Select w/ connected=true, readOnly=false. Make changes to DS by invoking DS.delete(). Call DS.sync(). SQLRuntimeException should be thrown.

      Testcase source (test method & interface only):
      ===============================================
      interface I_Query001 extends BaseQuery {
          @Select(sql="SELECT * from dataset002", readOnly=false, connected=true)
          DataSet<PersonDO> getAllPersons() throws SQLRuntimeException;
      }

          /**
           * Main test method.
           */
          private void doTest() throws DBConnectionException, TestFailureException {

              //loads the class and creates Connection object
              System.out.println(this.getClass().getName()+
                                 ".doTest() : getting Connection object.... ");
              Connection con = utils.getJdbcConnection();

              I_Query001 query = null;
              DataSet<PersonDO> rows = null;

              try {
                  System.out.println(this.getClass().getName()+
                                     ".doTest() : getting QueryObject handle(JDBC 3.0)....");
                  //this invocation is for JDBC 3.0 compliant drivers
                  query = QueryObjectFactory.createQueryObject(I_Query001.class, con);
                  System.out.println(this.getClass().getName()+
                                     ".doTest() : got QueryObject handle(JDBC 3.0) ");
              } catch (SQLException sqlEx) {
                  System.err.println(this.getClass().getName()+
                                     ": SQLException caught "+sqlEx.getMessage());
                  //free the resources
                  utils.closeConnection(con);
                  throw new TestFailureException
                      ("Exception when QueryObjectFactory.createQueryObject. [Message="+
                       sqlEx.getMessage()+"]", sqlEx);
              }

              //get the DataSet object
              System.out.println(this.getClass().getName()+".doTest() : Executing @Query....");
              try {
                  rows = query.getAllPersons();
              } catch (SQLRuntimeException ex) {
                  //Incase of any exceptions, close the connection and throw TestFailureException
                  utils.closeConnection(con);
                  throw new TestFailureException
                      ("SQLRuntimeException when getting DataSet by executing @Query. [Message="+
                        ex.getMessage()+"]", ex);
              }

              //do some generic checks. common for lot of tests...
              if (null == rows || rows.size() == 0) {
                  System.out.println("Dataset is null/empty : TEST FAILED");
                  utils.closeConnection(con);
                  throw new TestFailureException("Dataset returned by @Query is null/empty.");
              }

              int initial_row_size = rows.size();
              System.out.println(this.getClass().getName()+
                                 ".doTest() : DataSet.size="+initial_row_size);
              //for this test, we will try to change contents of DataSet and invoke sync() method.
              System.out.println(this.getClass().getName()+".doTest() : Calling DataSet.delete().");

              try {
                  for (PersonDO p : rows) {
                      if (p.getId()==1)
                          rows.delete();
                  }

                  System.out.println("check isConnected()=" + rows.isConnected());
                  DatabaseMetaData dsmd = con.getMetaData();
                  System.out.println("dsmd.ownDeletesAreVisible(..)=" +
                                      dsmd.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE));

                  System.out.println(this.getClass().getName()+
                                     ".doTest() : Calling DataSet.sync()...");
                  rows.sync();
              } catch (Exception ex) {
                  //if exception was thrown, it is the expected behaviour.
                  System.out.println(this.getClass().getName()+
                      ".doTest() : Caught SQLRuntimeException SQLException :"+ex.getMessage());
                  System.out.println(this.getClass().getName()+
                      ".doTest() : SQLException thrown when invoking DataSet.sync in connected " +
                      "Rowset . TEST PASSED");
                  //close the connection and return
                  ex.printStackTrace();
                  return;
              } finally {
                  utils.closeConnection(con);
              }

              //if here mark the test as FAILED
              System.out.println("No SQLRuntimeException thrown when invoking DataSet.sync() " +
                                 "in connected Rowset : TEST FAILED");
              throw new TestFailureException
                  ("No SQLException thrown when invoking DataSet.sync() in connected Rowset . ");
          }

      In the above code, the call to:

      rows.sync()

      should throw an SQLRuntimeException because the annotation has connected=true.

      How to reproduce:
      =================
      1) cd /net/cady/export/sqa/js159705/jdbc/bugs/[bug id]
      2) ksh Run_Standalone.ksh
      3) Results will be in workDir/$username.$os.$arch/$testcase/ directory.

      Other options:
      To change other options (such as changing the JDK, database, connection string), edit the setup file in that directory before running Run_Standalone.ksh.

            ssharmasunw Sushmita Sharma (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: