Transactions in ImageViewer

This commit is contained in:
Peter Mount 1999-05-18 06:07:25 +00:00
parent 21e03211cf
commit d261a5ec86
2 changed files with 10 additions and 0 deletions

View 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 Tue May 18 00:00:00 BST 1999
- Just after committing, I realised why internationalisation isn't - Just after committing, I realised why internationalisation isn't
working. This is now fixed (in the Makefile). working. This is now fixed (in the Makefile).

View File

@ -192,6 +192,9 @@ public class ImageViewer implements ItemListener
// Create a statement // Create a statement
stat = db.createStatement(); stat = db.createStatement();
// Set the connection to use transactions
db.setAutoCommit(false);
// Also, get the LargeObjectManager for this connection // Also, get the LargeObjectManager for this connection
lom = ((postgresql.Connection)db).getLargeObjectAPI(); lom = ((postgresql.Connection)db).getLargeObjectAPI();
@ -209,6 +212,7 @@ public class ImageViewer implements ItemListener
try { try {
stat.executeUpdate("create table images (imgname name,imgoid oid)"); stat.executeUpdate("create table images (imgname name,imgoid oid)");
label.setText("Initialised database"); label.setText("Initialised database");
db.commit();
} catch(SQLException ex) { } catch(SQLException ex) {
label.setText(ex.toString()); label.setText(ex.toString());
} }
@ -310,6 +314,7 @@ public class ImageViewer implements ItemListener
// our own thread // our own thread
stat = db.createStatement(); stat = db.createStatement();
stat.executeUpdate("insert into images values ('"+name+"',"+oid+")"); stat.executeUpdate("insert into images values ('"+name+"',"+oid+")");
db.commit();
// Finally refresh the names list, and display the current image // Finally refresh the names list, and display the current image
ImageViewer.this.refreshList(); ImageViewer.this.refreshList();
@ -372,9 +377,11 @@ public class ImageViewer implements ItemListener
// Finally delete any entries for that name // Finally delete any entries for that name
stat.executeUpdate("delete from images where imgname='"+currentImage+"'"); stat.executeUpdate("delete from images where imgname='"+currentImage+"'");
db.commit();
label.setText(currentImage+" deleted"); label.setText(currentImage+" deleted");
currentImage=null; currentImage=null;
db.commit();
refreshList(); refreshList();
} catch(SQLException ex) { } catch(SQLException ex) {
label.setText(ex.toString()); label.setText(ex.toString());