@Override public void abort() { fileGraph.clear(); fileGraph.readModelFrom( fileGraph.model, true, checkPointFile ); checkPointFile.delete(); inTransaction = false; }
/** Answer a new, anonynous FileGraph. See FileGraph.create(). @return a new anonymous FileGraph */ @Override public Graph createGraph() { return FileGraph.create(); }
@Override public boolean accept( File file, String name ) { return !new File( file, name ).isDirectory() && FileGraph.isPlausibleGraphName( name ); } }; }
/** The file intermediate has the new file contents. We want to move them to the current file. renameTo doesn't have a powerful enough semantics, so we anticipate failure and attempt to bypass it ... <p> If the rename works, that's fine. If it fails, we delete the old file if it exists, and try again. */ protected void updateFrom( File targetName, File intermediate ) { if (intermediate.renameTo( targetName ) == false) { if (targetName.exists()) mustDelete( targetName ); mustRename( intermediate, targetName ); } }
@Override public void commit() { fileGraph.saveContents( fileGraph.name ); checkPointFile.delete(); inTransaction = false; }
public Model createFileModel( File fullName, String lang, boolean create, boolean strict ) { NotifyOnClose notify = NotifyOnClose.ignore; Graph fileGraph = new FileGraph( notify, fullName, lang, create, strict ); return ModelFactory.createModelForGraph( fileGraph ); }
protected void readModel( Model m, boolean strict ) { readModelFrom( m, strict, name ); }
/** Construct a new FileGraph who's name is given by the specified File, If create is true, this is a new file, and any existing file will be destroyed; if create is false, this is an existing file, and its current contents will be loaded. The language code for the file is supplied. @param f the File naming the associated file-system file @param lang the language string for the file @param create true to create a new one, false to read an existing one @param strict true to throw exceptions for create: existing, open: not found @param style the reification style for the graph */ public FileGraph( NotifyOnClose notify, File f, String lang, boolean create, boolean strict ) { this.name = f; this.notify = notify; this.model = new ModelCom( this ); this.lang = lang; if (create) { if (f.exists() && strict) throw new AlreadyExistsException( f.toString() ); } else readModel( this.model, strict ); }
@Override public Graph createGraph( String name, boolean strict ) { File f = withRoot( name ); FileGraph already = created.get( f ); if (already == null) return remember( f, new FileGraph( this, f, true, strict ) ); else { if (strict) throw new AlreadyExistsException( name ); else return already.openAgain(); } }
@Override public void begin() { if (inTransaction) throw new JenaException( "nested transactions not supported" ); else { checkPointFile = new File( checkPointName( fileGraph.name ) ); checkPointFile.deleteOnExit(); fileGraph.saveContents( checkPointFile ); inTransaction = true; } }
public static FileGraph create() { return new FileGraph( FileUtils.tempFileName( "anonymousFileGraph", ".rdf" ), true, true ); }
/** Write out and then close this FileGraph. */ @Override public void close() { saveContents( name ); super.close(); if (count == 0) notify.notifyClosed( name ); }