1 6 7 package com.hp.hpl.jena.graph.impl; 8 9 import java.io.File ; 10 11 import com.hp.hpl.jena.graph.TransactionHandler; 12 import com.hp.hpl.jena.shared.JenaException; 13 14 24 public class FileGraphTransactionHandler 25 extends TransactionHandlerBase implements TransactionHandler 26 { 27 protected boolean inTransaction; 28 protected FileGraph fileGraph; 29 protected File checkPointFile; 30 31 public FileGraphTransactionHandler( FileGraph fileGraph ) 32 { this.fileGraph = fileGraph; } 33 34 public boolean transactionsSupported() 35 { return true; } 36 37 public void begin() 38 { if (inTransaction) 39 throw new JenaException( "nested transactions not supported" ); 40 else 41 { checkPointFile = new File ( checkPointName( fileGraph.name ) ); 42 checkPointFile.deleteOnExit(); 43 fileGraph.saveContents( checkPointFile ); 44 inTransaction = true; } } 45 46 protected String checkPointName( File name ) 47 { 48 String path = name.getPath(); 49 int pos = path.lastIndexOf( File.separatorChar ); 50 String start = path.substring( 0, pos + 1 ); 51 String finish = path.substring( pos + 1 ); 52 return start + "checkPoint-" + finish; 53 } 54 55 public void abort() 56 { fileGraph.getBulkUpdateHandler().removeAll(); 57 fileGraph.readModelFrom( fileGraph.model, true, checkPointFile ); 58 checkPointFile.delete(); 59 inTransaction = false; } 60 61 public void commit() 62 { fileGraph.saveContents( fileGraph.name ); 63 checkPointFile.delete(); 64 inTransaction = false; } 65 66 } 67 68 | Popular Tags |