Removed custom code for starting and managing database transactions, and used standar...
authorMarco Zanon <info@marcozanon.com>
Thu, 26 Jan 2012 22:17:25 +0000 (22:17 +0000)
committerMarco Zanon <info@marcozanon.com>
Thu, 26 Jan 2012 22:17:25 +0000 (22:17 +0000)
src/java/com/marcozanon/macaco/sql/MSqlConnection.java

index f9652cc57b1b403906a436e7b51f168ef82cdf70..3b5779b3ef335f6315a3266ab83ce3ae3bf3aa8b 100644 (file)
@@ -166,7 +166,7 @@ public class MSqlConnection extends MObject {
             throw new MTransactionSqlException("Nested transactions not allowed.");
         }
         try {
-            this.getConnectionReference().createStatement().executeUpdate("START TRANSACTION");
+            this.getConnectionReference().setAutoCommit(false);
             this.setTransactionStatus(MSqlConnection.TransactionStatus.SUCCESSFUL);
         }
         catch (SQLException exception) {
@@ -176,10 +176,10 @@ public class MSqlConnection extends MObject {
 
     public void rollBackTransaction() throws MTransactionSqlException {
         if (MSqlConnection.TransactionStatus.CLOSED == this.getTransactionStatus()) {
-            throw new MTransactionSqlException("Could not find transaction.");
+            throw new MTransactionSqlException("Transaction not started.");
         }
         try {
-            this.getConnectionReference().createStatement().executeUpdate("ROLLBACK");
+            this.getConnectionReference().rollback();
             this.setTransactionStatus(MSqlConnection.TransactionStatus.CLOSED);
         }
         catch (SQLException exception) {
@@ -192,7 +192,7 @@ public class MSqlConnection extends MObject {
         switch (this.getTransactionStatus()) {
             case SUCCESSFUL:
                 try {
-                    this.getConnectionReference().createStatement().executeUpdate("COMMIT");
+                    this.getConnectionReference().commit();
                     this.setTransactionStatus(MSqlConnection.TransactionStatus.CLOSED);
                     return MSqlConnection.TransactionStatus.SUCCESSFUL;
                 }
@@ -204,7 +204,7 @@ public class MSqlConnection extends MObject {
                 this.rollBackTransaction();
                 return MSqlConnection.TransactionStatus.FAILED;
             default: // instead of "case CLOSED:" (necessary to avoid Java compilation errors)
-                throw new MTransactionSqlException("Could not find transaction.");
+                throw new MTransactionSqlException("Transaction not started.");
         }
     }