User: dsundstrom
  Date: 02/02/11 22:15:17

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc
                        JDBCStartCommand.java
  Log:
  Removed wanker log.info protection code.
  Changed addForeignKeyConstraint to assure that the connection and statement
  are closed before the transaction is committed. This is required for XA
  connections.
  
  Revision  Changes    Path
  1.21      +41 -41    
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java
  
  Index: JDBCStartCommand.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCStartCommand.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- JDBCStartCommand.java     9 Feb 2002 16:09:23 -0000       1.20
  +++ JDBCStartCommand.java     12 Feb 2002 06:15:17 -0000      1.21
  @@ -40,7 +40,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Joe Shevland</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Justin Forder</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Michel de Groot</a>
  - * @version $Revision: 1.20 $
  + * @version $Revision: 1.21 $
    */
   public class JDBCStartCommand {
   
  @@ -128,12 +128,10 @@
            String tableName,
            String sql) throws DeploymentException {
   
  -      boolean infoEnabled = log.isInfoEnabled();
   
         // does this table already exist
         if(tableExists(dataSource, tableName)) {
  -         if (infoEnabled)
  -            log.info("Table '" + tableName + "' already exists");
  +         log.info("Table '" + tableName + "' already exists");
            return;
         }
   
  @@ -141,35 +139,31 @@
         Statement statement = null;
   
         // since we use the pools, we have to do this within a transaction
  -      try 
  -      {
  +      try {
            manager.getContainer().getTransactionManager().begin ();         
  +      } catch (Exception e) {
  +         throw new DeploymentException("Could not get transaction to create " +
  +               "table in", e);
         }
  -      catch (Exception e)
  -      {
  -         log.error("Could not get transaction to create table in", e);
  -         throw new DeploymentException("Could not get transaction to create table 
in", e);
  -      } // end of try-catch
         try {
  -         // get the connection
  -         con = dataSource.getConnection();
            try {        
  +            // get the connection
  +            con = dataSource.getConnection();
  +
               // create the statement
               statement = con.createStatement();
            
  -         // execute sql
  +            // execute sql
               log.debug("Executing SQL: " + sql);
               statement.executeUpdate(sql);
  -         }
  -         finally
  -         {
  +         } finally {
  +            // make sure to close the connection and statement before 
  +            // comitting the transaction or XA will break
               JDBCUtil.safeClose(statement);
               JDBCUtil.safeClose(con);
  -         } // end of finally
  +         }
            manager.getContainer().getTransactionManager().commit ();
  -      } 
  -      catch(Exception e) 
  -      {
  +      } catch(Exception e) {
            log.debug("Could not create table " + tableName);
            try {
               manager.getContainer().getTransactionManager().rollback ();
  @@ -179,8 +173,7 @@
            throw new DeploymentException("Error while creating table", e);
         }
         // success
  -      if (infoEnabled)
  -         log.info("Created table '" + tableName + "' successfully.");
  +      log.info("Created table '" + tableName + "' successfully.");
         Set createdTables = (Set)manager.getApplicationData(CREATED_TABLES_KEY);
         createdTables.add(tableName);
      }
  @@ -296,7 +289,6 @@
                  "relationshipRolename=" +
                  cmrField.getMetaData().getRelationshipRoleName());
         }
  -
      }
   
      private void addForeignKeyConstraint(
  @@ -329,28 +321,36 @@
            b};
         String sql = fkConstraint.getFunctionSql(args);
   
  +      // since we use the pools, we have to do this within a transaction
  +      try {
  +         manager.getContainer().getTransactionManager().begin ();         
  +      } catch (Exception e) {
  +         throw new DeploymentException("Could not get transaction to create " +
  +               "table in", e);
  +      }
  +
         Connection con = null;
         Statement statement = null;
         try {
  -         // since we use the pools, we have to do this within a transaction
  -         manager.getContainer().getTransactionManager().begin();
  -
  -         // get the connection
  -         con = dataSource.getConnection();
  +         try {
  +            // get the connection
  +            con = dataSource.getConnection();
            
  -         // create the statement
  -         statement = con.createStatement();
  +            // create the statement
  +            statement = con.createStatement();
            
  -         // execute sql
  -         log.debug("Executing SQL: " + sql);
  -         statement.executeUpdate(sql);
  +            // execute sql
  +            log.debug("Executing SQL: " + sql);
  +            statement.executeUpdate(sql);
  +         } finally {
  +            // make sure to close the connection and statement before 
  +            // comitting the transaction or XA will break
  +            JDBCUtil.safeClose(statement);
  +            JDBCUtil.safeClose(con);
  +         }
   
            // commit the transaction
            manager.getContainer().getTransactionManager().commit();
  -
  -         // success
  -         if (log.isInfoEnabled())
  -            log.info("Added foreign key constriant to table '" + tableName);
         } catch(Exception e) {
            log.debug("Could not add foreign key constriant: table=" + tableName);
            try {
  @@ -360,9 +360,9 @@
            }  
            throw new DeploymentException("Error while adding foreign key " +
                  "constraint", e);
  -      } finally {
  -         JDBCUtil.safeClose(statement);
  -         JDBCUtil.safeClose(con);
         }
  +
  +      // success
  +      log.info("Added foreign key constriant to table '" + tableName);
      }
   }
  
  
  

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

Reply via email to