3 Replies Latest reply on Mar 3, 2002 10:46 PM by ipozeng

    about rowset

    ipozeng

      Hi,friends
      Does CachedRowSet support CMT? When setting transaction attribute to Bean,it works fine.However JBoss-2.4.4 will raise the error as below using CMT:
      javax.transaction.TransactionRolledbackException: Cannot commit a transactional connection: See JDBC 2.0 Optional Package Specification section 7.1.
      the code snippet is:
      ...
      public void updateCoffees(RowSet rs) throws SQLException
      {
      Connection con = null;

      try {
      CachedRowSet crs = (CachedRowSet)rs;
      // moves the changes back to the database
      con = getConnection();
      crs.acceptChanges(con);
      }catch(Exception e) {
      EJBException re = new EJBException(e.getMessage());
      throw re;
      }
      finally {
      if (con != null) con.close();
      }
      }
      ...
      i think acceptChanges() calls commit which is forbidden when using CMT.
      Is it right? if so how can i use CachedRowSet when using CMT?
      what a great thing the Open Source is! I really want to get the source code of rowset.jar :)

      Best Regards!

        • 1. Re: about rowset
          ipozeng

          Now i really know why the CachedRowSet cannot be used in CMT bean by using jad tool.The following is code snippet produced by jad:
          ...
          public boolean writeData(RowSetInternal rowsetinternal)
          throws SQLException
          {
          boolean flag = false;
          boolean flag1 = false;
          PreparedStatement preparedstatement = null;
          CachedRowSet cachedrowset = (CachedRowSet)rowsetinternal;
          con = ((RowSetReaderImpl)cachedrowset.getReader()).connect(rowsetinternal);
          if(con == null)
          throw new SQLException("Unable to get Connection");
          if(con.getAutoCommit())
          con.setAutoCommit(false);
          con.setTransactionIsolation(cachedrowset.getTransactionIsolation());
          initSQLStatements(cachedrowset);
          preparedstatement = con.prepareStatement(insertCmd);
          if(callerColumnCount < 1)
          {
          if(((RowSetReaderImpl)cachedrowset.getReader()).getCloseConnection())
          con.close();
          return true;
          }
          flag1 = cachedrowset.getShowDeleted();
          cachedrowset.setShowDeleted(true);
          cachedrowset.beforeFirst();
          while(cachedrowset.next())
          if((!cachedrowset.rowDeleted() || !cachedrowset.rowInserted()) &&
          (cachedrowset.rowDeleted() ? (flag = deleteOriginalRow(cachedrowset)) :
          cachedrowset.rowInserted() ?
          (flag = insertNewRow(cachedrowset, preparedstatement)) :
          cachedrowset.rowUpdated() && (flag = updateOriginalRow(cachedrowset))))
          break;
          preparedstatement.close();
          cachedrowset.setShowDeleted(flag1);
          if(flag)
          {
          con.rollback(); <----- donot allowed using CMT
          if(((RowSetReaderImpl)cachedrowset.getReader()).getCloseConnection())
          con.close();
          return false;
          }
          con.commit(); <----- donot allowed using CMT
          if(((RowSetReaderImpl)cachedrowset.getReader()).getCloseConnection())
          con.close();
          return true;
          }
          ....
          By comment the commit and rollback call it works great when using CMT
          jad is a wonderful tool however i am uncomfortable because i feel it is so easy to decompile class file
          Moreover since sun doesnot prevent it from decompiling by obfuscating it why doesnot sun make it open source ?

          BTW,when compiling the jad output you must make jboss-jdbc_ext.jar,xerces.jar be in classpath.For me i still cannot compile WebRowSet.java and Xml*.java as i cannot find out which jar file contains com.sun.xml.parser.* classes.

          • 2. Re: about rowset
            zeroman

            It seems to me what you are not use RowSet properly.
            I mean acceptChanges()? try to remove it.

            It must work because we use this library in the project and everything work fine in the EJB.

            • 3. Re: about rowset
              ipozeng

              >> mean acceptChanges()? try to remove it.

              If so how do i update the underlying data?


              Regards!