/** Answer a ModelMaker that constructs memory-based Models that are backed by files in the root directory. The Model is loaded from the file when it is opened, and when the Model is closed it is written back. @param root the name of the directory in which the backing files are held @return a ModelMaker linked to the files in the root */ public static ModelMaker createFileModelMaker( String root ) { return new ModelMakerImpl( new FileGraphMaker( root ) ); }
@Override public void close() { if (deleteOnClose) { deleteFiles( created.keySet().iterator() ); deleteFiles( toDelete.iterator() ); } }
private File withRoot( String name ) { return new File( fileBase, toFilename( name ) ); }
{ @Override public String map1( String x ) { return toGraphname( x ); } };
@Override public boolean hasGraph( String name ) { File f = withRoot( name ); return created.containsKey( f ) || f.exists(); }
/** Answer an iterator over the names of graphs in the FileGraphMaker. This is all the names of freshly-created graphs, plus the names of any files in the fileBase that might be RDF files. "Might" is weaker than we'd like for now. @see com.hp.hpl.jena.graph.GraphMaker#listGraphs() */ @Override public ExtendedIterator<String> listGraphs() { String [] fileNames = new File( fileBase ).list( graphName() ); Set<String> allNames = CollectionFactory.createHashedSet( Arrays.asList( fileNames ) ); Iterator<File> it = created.keySet().iterator(); while (it.hasNext()) allNames.add( it.next().getName() ); return WrappedIterator.create( allNames.iterator() ) .mapWith( unconvert ); } }
@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(); } }
protected File getFileName( Resource root ) { String name = getModelName( root ); boolean mapName = getBoolean( root, JA.mapName, false ); String dir = getDirectoryName( root ); return new File( dir, (mapName ? FileGraphMaker.toFilename( name ): name) ); }
/** Answer a ModelMaker that constructs memory-based Models that are backed by files in the root directory. The Model is loaded from the file when it is opened, and when the Model is closed it is written back. @param root the name of the directory in which the backing files are held @param style the desired reification style @return a ModelMaker linked to the files in the root */ @Deprecated public static ModelMaker createFileModelMaker( String root, ReificationStyle style ) { return new ModelMakerImpl( new FileGraphMaker( root ) ); }