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

Exception when running acceptChanges with custom SyncProvider

    Details

    • Subcomponent:
    • Resolved In Build:
      b114
    • CPU:
      generic
    • OS:
      generic

      Description

      It turned out that an exception occurs when a write data action is being delegated to a custom rowset SyncProvider for any of the Cashed rowset implementations.

      Here a minimized test that demonstrates the problem.

      ---------------- Test.java -----------------------
      import java.io.Serializable;
      import java.sql.SQLException;
      import java.sql.Savepoint;
      import java.sql.Types;
      import javax.sql.rowset.spi.*;
      import javax.sql.rowset.*;
      import javax.sql.*;

      public class Test extends SyncProvider implements RowSetReader,
              TransactionalWriter, Cloneable, Serializable, RowSetListener {

          static {
              try {
                  SyncFactory.registerProvider(Test.class.getName());
              } catch (SyncFactoryException ex) {
                  throw new RuntimeException(ex);
              }
          }
          protected int datasource_lock = SyncProvider.DATASOURCE_NO_LOCK;

          public void setDataSourceLock(int datasource_lock)
                  throws SyncProviderException {
              this.datasource_lock = datasource_lock;
          }

          public int supportsUpdatableView() {
              return SyncProvider.UPDATABLE_VIEW_SYNC;
          }

          public String getVersion() {
              return "1.0";
          }

          public String getVendor() {
              return "Spb JCK Team";
          }

          public RowSetWriter getRowSetWriter() {
              return this;
          }

          public RowSetReader getRowSetReader() {
              return this;
          }

          public String getProviderID() {
              return getClass().getName();
          }

          public int getProviderGrade() {
              return SyncProvider.GRADE_NONE;
          }

          public int getDataSourceLock() throws SyncProviderException {
              return datasource_lock;
          }

          public boolean writeData(RowSetInternal caller) throws
                  java.sql.SQLException {
              System.out.println("writeData");
              return true;
          }

          public void readData(RowSetInternal caller) throws java.sql.SQLException {
              System.out.println("readData");
          }

          public void rowSetChanged(RowSetEvent event) {
              System.out.println("rowSetChanged");
          }

          public void rowChanged(RowSetEvent event) {
              System.out.println("rowChanged");
          }

          public void cursorMoved(RowSetEvent event) {
              System.out.println("cursorMoved");
          }

          @Override
          public Object clone() throws CloneNotSupportedException {
              return super.clone();
          }

          public static void main(String[] argv) throws Exception {
              final CachedRowSet crs = new com.sun.rowset.CachedRowSetImpl();
              
              crs.setSyncProvider(Test.class.getName());
              crs.setType(RowSet.TYPE_SCROLL_INSENSITIVE);
              RowSetMetaDataImpl rsmdi = new RowSetMetaDataImpl();
              rsmdi.setColumnCount(1);
              rsmdi.setColumnName(1, "_char_");
              rsmdi.setColumnType(1, Types.CHAR);
              crs.setMetaData(rsmdi);
              crs.moveToInsertRow();
              crs.updateString(1, "Char value");
              crs.insertRow();
              crs.moveToCurrentRow();

              System.out.println("READY");
              crs.acceptChanges();
              System.out.println("DONE");
          }

          public void commit() throws SQLException {

          }

          public void rollback() throws SQLException {

          }

          public void rollback(Savepoint s) throws SQLException {
              
          }

      }
      ---------------------------------------------------

      <ag153348@spb-piker> java7 -showversion -cp /net/spb-piker/export/users/ag153348/trash/JavaApplication5/build/classes Test
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b109)
      Java HotSpot(TM) Server VM (build 19.0-b06, mixed mode)

      READY
      writeData
      Exception in thread "main" java.lang.ClassCastException: Test cannot be cast to com.sun.rowset.internal.CachedRowSetWriter
      at com.sun.rowset.CachedRowSetImpl.acceptChanges(CachedRowSetImpl.java:889)
      at Test.main(Test.java:101)


      It looks like this program fails due to incorrect type casting of the RowSetWriter instance to the internal type.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lancea Lance Andersen
                Reporter:
                agavrilosunw Alexey Gavrilov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: