Transactions in ImageViewer
authorPeter Mount
Tue, 18 May 1999 06:07:25 +0000 (06:07 +0000)
committerPeter Mount
Tue, 18 May 1999 06:07:25 +0000 (06:07 +0000)
src/interfaces/jdbc/CHANGELOG
src/interfaces/jdbc/example/ImageViewer.java

index 130ecb29fffacb8e52eac6c21b0a8eeea68c0460..29b834bfeb8ff3bd6b096820ceeb2e209323b7ac 100644 (file)
@@ -1,3 +1,6 @@
+Tue May 18 07:00:00 BST 1999
+   - Set the ImageViewer application to use transactions
+
 Tue May 18 00:00:00 BST 1999
    - Just after committing, I realised why internationalisation isn't
      working. This is now fixed (in the Makefile).
index 8f6f4c5e68f4f522b0a0ea412f05dc389e2ee523..56166807d70515623aa189158dd61e400b23622d 100644 (file)
@@ -192,6 +192,9 @@ public class ImageViewer implements ItemListener
     // Create a statement
     stat = db.createStatement();
     
+    // Set the connection to use transactions
+    db.setAutoCommit(false);
+    
     // Also, get the LargeObjectManager for this connection
     lom = ((postgresql.Connection)db).getLargeObjectAPI();
     
@@ -209,6 +212,7 @@ public class ImageViewer implements ItemListener
     try {
       stat.executeUpdate("create table images (imgname name,imgoid oid)");
       label.setText("Initialised database");
+      db.commit();
     } catch(SQLException ex) {
       label.setText(ex.toString());
     }
@@ -310,6 +314,7 @@ public class ImageViewer implements ItemListener
      // our own thread
      stat = db.createStatement();
      stat.executeUpdate("insert into images values ('"+name+"',"+oid+")");
+     db.commit();
      
      // Finally refresh the names list, and display the current image
      ImageViewer.this.refreshList();
@@ -372,9 +377,11 @@ public class ImageViewer implements ItemListener
       
       // Finally delete any entries for that name
       stat.executeUpdate("delete from images where imgname='"+currentImage+"'");
+      db.commit();
       
       label.setText(currentImage+" deleted");
       currentImage=null;
+      db.commit();
       refreshList();
     } catch(SQLException ex) {
       label.setText(ex.toString());