User: dsundstrom
  Date: 01/11/15 16:47:50

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc JDBCStopCommand.java
                        JDBCDestroyCommand.java
  Log:
  Move all code from destroy to stop.
  
  Revision  Changes    Path
  1.3       +71 -10    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStopCommand.java
  
  Index: JDBCStopCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStopCommand.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JDBCStopCommand.java      2001/08/03 17:15:46     1.2
  +++ JDBCStopCommand.java      2001/11/16 00:47:50     1.3
  @@ -7,26 +7,87 @@
    
   package org.jboss.ejb.plugins.cmp.jdbc;
   
  +import java.sql.Connection;
  +import java.sql.DatabaseMetaData;
  +import java.sql.ResultSet;
  +import java.sql.SQLException;
   import org.jboss.ejb.plugins.cmp.StopCommand;
  +import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge;
   
   /**
  - * JDBCStopCommand does nothing.
  + * JDBCStopCommand drops the table for this entity if specified in the xml.
    *    
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
  -public class JDBCStopCommand implements StopCommand
  -{
  -   // Constructors --------------------------------------------------
  +public class JDBCStopCommand extends JDBCUpdateCommand implements StopCommand {
  +
  +   public JDBCStopCommand(JDBCStoreManager manager) {
  +      super(manager, "Stop");
  +   }
      
  -   public JDBCStopCommand(JDBCStoreManager manager)
  -   {
  +   public void execute() {
  +      if(entityMetaData.getRemoveTable()) {
  +         log.debug("Droping tables for entity " + entity.getEntityName());
  +         dropTable(entityMetaData.getTableName());
  +
  +         // drop relation tables
  +         JDBCCMRFieldBridge[] cmrFields = entity.getJDBCCMRFields();
  +         for(int i=0; i<cmrFields.length; i++) {
  +            // if it uses a relation-table drop it
  +            if(!cmrFields[i].hasForeignKey() && 
  +                  !cmrFields[i].getRelatedCMRField().hasForeignKey()) {
  +
  +               dropTable(cmrFields[i].getRelationTableName());
  +            }
  +         }
  +      }
      }
      
  -   // StopCommand implementation ---------------------------------
  +   public void dropTable(String tableName) {
  +      Connection con = null;
  +      ResultSet rs = null;
  +      try {
  +         con = manager.getConnection();
  +         DatabaseMetaData dmd = con.getMetaData();
  +         rs = dmd.getTables(con.getCatalog(), null, tableName, null);
  +         if(!rs.next()) {
  +            // table already deleted
  +            return;
  +         }
  +      } catch(SQLException e) {
  +         // ignore - bad driver
  +         return;
  +      } finally {
  +         JDBCUtil.safeClose(rs);
  +         JDBCUtil.safeClose(con);
  +      }
  +
  +      try {
  +         // since we use the pools, we have to do this within a transaction
  +         manager.getContainer().getTransactionManager().begin();
  +         jdbcExecute("DROP TABLE " + tableName);
  +         manager.getContainer().getTransactionManager().commit();
  +         log.info("Dropped table '" + tableName + "' successfully.");
  +      } catch (Exception e) {
  +         log.debug("Could not drop table " + tableName + ": " + e.getMessage());
  +         try {
  +            manager.getContainer().getTransactionManager().rollback ();
  +         } catch (Exception _e) {
  +            log.error("Could not roll back transaction: "+ _e.getMessage());
  +         }
  +      }
  +   }
      
  -   public void execute()
  -   {
  +   protected String getSQL(Object sql) throws Exception {
  +      return (String) sql;
  +   }
  +      
  +   protected Object handleResult(int rowsAffected, Object argOrArgs) 
  +      throws Exception
  +   {     
  +      return null;
      }
   }
  
  
  
  1.7       +3 -72     
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDestroyCommand.java
  
  Index: JDBCDestroyCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCDestroyCommand.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JDBCDestroyCommand.java   2001/09/11 18:35:00     1.6
  +++ JDBCDestroyCommand.java   2001/11/16 00:47:50     1.7
  @@ -7,91 +7,22 @@
   
   package org.jboss.ejb.plugins.cmp.jdbc;
   
  -import java.sql.Connection;
  -import java.sql.DatabaseMetaData;
  -import java.sql.ResultSet;
  -import java.sql.SQLException;
   import org.jboss.ejb.plugins.cmp.DestroyCommand;
  -import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge;
   
   /**
  - * JDBCDestroyCommand drops the table for this entity if specified in the xml.
  + * JDBCDestroyCommand does nothing.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
    * @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 JDBCDestroyCommand extends JDBCUpdateCommand implements DestroyCommand 
{
  -   // Constructors --------------------------------------------------
  -   
  +public class JDBCDestroyCommand implements DestroyCommand {
      public JDBCDestroyCommand(JDBCStoreManager manager) {
  -      super(manager, "Destroy");
      }
      
  -   // DestroyCommand implementation ------------------------------
  -   
      public void execute() {
  -      if(entityMetaData.getRemoveTable()) {
  -         log.debug("Droping tables for entity " + entity.getEntityName());
  -         dropTable(entityMetaData.getTableName());
  -
  -         // drop relation tables
  -         JDBCCMRFieldBridge[] cmrFields = entity.getJDBCCMRFields();
  -         for(int i=0; i<cmrFields.length; i++) {
  -            if(!cmrFields[i].hasForeignKey() && 
!cmrFields[i].getRelatedCMRField().hasForeignKey()) {
  -               if(cmrFields[i].getRelationTableName() == null)  log.debug("Table 
name null for cmr field " + cmrFields[i].getFieldName());
  -               dropTable(cmrFields[i].getRelationTableName());
  -            }
  -         }
  -      }
  -   }
  -   
  -   public void dropTable(String tableName) {
  -         Connection con = null;
  -      ResultSet rs = null;
  -      try {
  -         con = manager.getConnection();
  -         DatabaseMetaData dmd = con.getMetaData();
  -         rs = dmd.getTables(con.getCatalog(), null, tableName, null);
  -         if(!rs.next()) {
  -            // table already deleted
  -            return;
  -         }
  -      } catch(SQLException e) {
  -         // ignore - bad driver
  -         return;
  -      } finally {
  -         JDBCUtil.safeClose(rs);
  -         JDBCUtil.safeClose(con);
  -      }
  -
  -      try {
  -         // since we use the pools, we have to do this within a transaction
  -         manager.getContainer().getTransactionManager().begin ();
  -         jdbcExecute("DROP TABLE " + tableName);
  -         manager.getContainer().getTransactionManager().commit ();
  -         log.info("Dropped table '" + tableName + "' successfully.");
  -      } catch (Exception e) {
  -         log.debug("Could not drop table " + tableName + ": " + e.getMessage());
  -         try {
  -            manager.getContainer().getTransactionManager().rollback ();
  -         } catch (Exception _e) {
  -            log.error("Could not roll back transaction: "+ _e.getMessage());
  -         }
  -      }
  -   }
  -   
  -   // JDBCUpdateCommand overrides -----------------------------------
  -   protected String getSQL(Object sql) throws Exception {
  -      return (String) sql;
  -   }
  -      
  -   protected Object handleResult(int rowsAffected, Object argOrArgs) 
  -      throws Exception
  -   {     
  -      return null;
      }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to