User: schulze 
  Date: 00/10/11 12:40:42

  Modified:    src/main/org/jboss/ejb/plugins/jaws/jdbc
                        JDBCInitCommand.java
  Log:
  provided the PersistenceManager init() and destroy() methods with transactions, so 
that the table creation/deletion commands will affect the database.
  Furthermore I replaced the ugly hack for the table detection in the JDBCInitCommand 
with a j2ee spec compilant version (should work with all drivers).
  
  Revision  Changes    Path
  1.7       +28 -23    
jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java
  
  Index: JDBCInitCommand.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/jaws/jdbc/JDBCInitCommand.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCInitCommand.java      2000/09/28 01:17:04     1.6
  +++ JDBCInitCommand.java      2000/10/11 19:40:41     1.7
  @@ -14,7 +14,9 @@
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  +import java.sql.DatabaseMetaData;
   
  +
   import org.jboss.ejb.plugins.jaws.JPMInitCommand;
   import org.jboss.ejb.plugins.jaws.metadata.CMPFieldMetaData;
   
  @@ -26,7 +28,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Justin Forder</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class JDBCInitCommand
      extends JDBCUpdateCommand
  @@ -65,29 +67,32 @@
         // Create table if necessary
         if (jawsEntity.getCreateTable())
         {
  -          boolean created = false;
  -          Connection con = null;
  -          Statement st = null;
  -          ResultSet rs = null;
  -          try {
  -              con = getConnection();
  -              st = con.createStatement();
  -              rs = st.executeQuery("SELECT COUNT(*) FROM 
"+jawsEntity.getTableName()+" WHERE 0=1");
  -              if(rs.next())
  +         // first check if the table already exists...
  +         // (a j2ee spec compatible jdbc driver has to fully 
  +         // implement the DatabaseMetaData)
  +         boolean created = false;
  +         Connection con = null;
  +         ResultSet rs = null;
  +         try 
  +         {
  +             con = getConnection();
  +             DatabaseMetaData dmd = con.getMetaData();
  +             rs = dmd.getTables(con.getCatalog(), null, jawsEntity.getTableName(), 
null);
  +             if (rs.next ())
                   created = true;
  -              rs.close();
  -              rs = null;
  -              st.close();
  -              st = null;
  -              con.close();
  -              con = null;
  -          } catch(SQLException e) {
  -              created = false;
  -          } finally {
  -              if(rs != null) try {rs.close();}catch(SQLException e) {}
  -              if(st != null) try {st.close();}catch(SQLException e) {}
  -              if(con != null) try {con.close();}catch(SQLException e) {}
  -          }
  +         
  +             rs.close ();
  +             con.close ();
  +         } 
  +         catch(Exception e) 
  +         {
  +            throw e;
  +         } 
  +         finally 
  +         {
  +             if(rs != null) try {rs.close(); rs = null;}catch(SQLException e) {}
  +             if(con != null) try {con.close();con = null;}catch(SQLException e) {}
  +         }
   
            // Try to create it
            if(created) {
  
  
  

Reply via email to