User: dsundstrom
Date: 02/04/12 11:09:07
Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc
JDBCStartCommand.java
Log:
Fixed bug identified in patch [ 533736 ] CMP 2 no start tx.
The problem was with attempting to start a transaction if one already
existed. The patch stoped the creation of a new transaction if one already
exits. Instead, I suspend the current transaction before the ddl and
create a new one. After the ddl I resume the original transaction.
Revision Changes Path
1.25 +76 -22
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.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- JDBCStartCommand.java 10 Apr 2002 15:18:43 -0000 1.24
+++ JDBCStartCommand.java 12 Apr 2002 18:09:07 -0000 1.25
@@ -21,6 +21,9 @@
import java.util.Set;
import javax.sql.DataSource;
import javax.ejb.EJBException;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import org.jboss.deployment.DeploymentException;
import org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMPFieldBridge;
@@ -40,7 +43,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.24 $
+ * @version $Revision: 1.25 $
*/
public class JDBCStartCommand {
@@ -137,17 +140,24 @@
return;
}
- Connection con = null;
- Statement statement = null;
-
// since we use the pools, we have to do this within a transaction
+
+ // suspend the current transaction
+ TransactionManager tm = manager.getContainer().getTransactionManager();
+ Transaction oldTransaction = null;
try {
- manager.getContainer().getTransactionManager().begin ();
- } catch (Exception e) {
- throw new DeploymentException("Could not get transaction to create " +
- "table in", e);
+ oldTransaction = tm.suspend();
+ } catch(Exception e) {
+ throw new DeploymentException("Could not suspend current " +
+ "transaction before creating table.", e);
}
+
try {
+ // start the new transaction
+ tm.begin();
+
+ Connection con = null;
+ Statement statement = null;
try {
// get the connection
con = dataSource.getConnection();
@@ -164,16 +174,36 @@
JDBCUtil.safeClose(statement);
JDBCUtil.safeClose(con);
}
- manager.getContainer().getTransactionManager().commit ();
+
+ // commit the new transaction
+ tm.commit();
} catch(Exception e) {
log.debug("Could not create table " + tableName);
+
+ // try to rollback the new transaction
try {
- manager.getContainer().getTransactionManager().rollback();
+ if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
+ tm.rollback();
+ }
} catch(Exception _e) {
log.error("Could not roll back transaction: ", e);
}
throw new DeploymentException("Error while creating table", e);
+ } finally {
+ try {
+ // suspend the new transaction
+ tm.suspend();
+
+ // resume the old transaction
+ if(oldTransaction != null) {
+ tm.resume(oldTransaction);
+ }
+ } catch(Exception e) {
+ throw new DeploymentException("Could not reattach original " +
+ "transaction after create table");
+ }
}
+
// success
log.info("Created table '" + tableName + "' successfully.");
Set createdTables = (Set)manager.getApplicationData(CREATED_TABLES_KEY);
@@ -324,20 +354,26 @@
String sql = fkConstraint.getFunctionSql(args);
// since we use the pools, we have to do this within a transaction
+ // suspend the current transaction
+ TransactionManager tm = manager.getContainer().getTransactionManager();
+ Transaction oldTransaction = null;
try {
- manager.getContainer().getTransactionManager().begin ();
- } catch (Exception e) {
- throw new DeploymentException("Could not get transaction to create " +
- "table in", e);
+ oldTransaction = tm.suspend();
+ } catch(Exception e) {
+ throw new DeploymentException("Could not suspend current " +
+ "transaction before alter table create foreign key.", e);
}
- Connection con = null;
- Statement statement = null;
try {
+ // start the new transaction
+ tm.begin();
+
+ Connection con = null;
+ Statement statement = null;
try {
// get the connection
con = dataSource.getConnection();
-
+
// create the statement
statement = con.createStatement();
@@ -351,18 +387,36 @@
JDBCUtil.safeClose(con);
}
- // commit the transaction
- manager.getContainer().getTransactionManager().commit();
+ // commit the new transaction
+ tm.commit();
} catch(Exception e) {
log.debug("Could not add foreign key constriant: table=" + tableName);
+
+ // try to rollback the new transaction
try {
- manager.getContainer().getTransactionManager().rollback ();
- } catch (Exception _e) {
+ if(tm.getStatus() != Status.STATUS_NO_TRANSACTION) {
+ tm.rollback();
+ }
+ } catch(Exception _e) {
log.error("Could not roll back transaction: ", e);
- }
+ }
throw new DeploymentException("Error while adding foreign key " +
"constraint", e);
+ } finally {
+ try {
+ // suspend the new transaction
+ tm.suspend();
+
+ // resume the old transaction
+ if(oldTransaction != null) {
+ tm.resume(oldTransaction);
+ }
+ } catch(Exception e) {
+ throw new DeploymentException("Could not reattach original " +
+ "transaction after create table");
+ }
}
+
// success
log.info("Added foreign key constriant to table '" + tableName);
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development