5 Replies Latest reply on Feb 28, 2002 7:45 PM by ipozeng

    Can i use CachedRowSet in EntityBean

    ipozeng

      Hi,friends
      Recently i dowloaded rowset.jar from sun.I feel the CachedRowSet is very adapted to be used to package data(Value Object ?).
      However i found the CachedRowSet can only be used in BMT & BMP Session Bean(wish i were wrong !)
      Please give me some suggestion about rowset.jar :
      What's its role?
      How to user it?
      .....

      Best Regards!

        • 1. Re: Can i use CachedRowSet in EntityBean
          l.g.

          There is a pattern on theserverside.com.
          You need to become a member (it`s free):
          http://www.theserverside.com/resources/review/ejbpatterns-datatransferrowset-sept3.zip

          • 2. Re: Can i use CachedRowSet in EntityBean
            ipozeng

            Thanks for the information you supplied! i will study it as soon as possible.

            Best Regards!

            • 3. Re: Can i use CachedRowSet in EntityBean
              ipozeng

              I donot know why the CachedRowSet doesnot support CMT :(
              .....
              When executing acceptChanges() it always reports
              "javax.transaction.TransactionRolledbackException: Cannot commit a transactional connection: See JDBC 2.0 Optional Package Specification section 7.1 (p25)" !

              i guess it called commit in acceptChanges() !

              Can i get its source code?

              Best Regards!

              • 4. Re: Can i use CachedRowSet in EntityBean
                taiwubrian

                I read the JavaDoc about CachedRowSet. As it describes, CachedRowSet can be used with any data source. You can populate data frim within an EJB CMP entity or session bean.

                Thanks for the info. I actually am using Collections and value objects to cache row sets. I can use any source of data. So far works for me. However, I would like to try a "standard" one.





                • 5. Re: Can i use CachedRowSet in EntityBean
                  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.