1 6 7 package com.hp.hpl.jena.db.impl; 8 9 import com.hp.hpl.jena.db.GraphRDB; 10 import com.hp.hpl.jena.db.IDBConnection; 11 import com.hp.hpl.jena.graph.*; 12 import com.hp.hpl.jena.graph.impl.*; 13 import com.hp.hpl.jena.shared.*; 14 import com.hp.hpl.jena.util.CollectionFactory; 15 import com.hp.hpl.jena.util.iterator.*; 16 import com.hp.hpl.jena.vocabulary.*; 17 18 import java.util.*; 19 20 28 29 public class GraphRDBMaker extends BaseGraphMaker 30 { 31 private IDBConnection c; 32 private int counter = 0; 33 private Set created = CollectionFactory.createHashedSet(); 34 int reificationStyle; 35 36 40 public GraphRDBMaker( IDBConnection c, ReificationStyle style ) 41 { 42 super( style ); 43 this.c = c; 44 this.reificationStyle = GraphRDB.styleRDB( style ); 45 } 46 47 51 public Node getMakerClass() 52 { return JenaModelSpec.RDBMakerSpec.asNode(); } 53 54 58 protected void augmentDescription( Graph g, Node self ) 59 {} 60 61 64 public Graph getGraph() 65 { if (defaultGraph == null) 66 defaultGraph = consGraph( null, !c.containsDefaultModel() ); 67 return defaultGraph; } 68 69 72 protected Graph defaultGraph = null; 73 74 81 public Graph createGraph() 82 { return createGraph( "anon_" + counter++ + "", false ); } 83 84 87 public Graph createGraph( String name, boolean strict ) 88 { 89 created.add( name ); 90 boolean fresh = strict || !hasGraph( name ); 91 return consGraph( name, fresh ); 92 } 93 94 98 public Graph openGraph( String name, boolean strict ) 99 { 100 boolean fresh = hasGraph( name ) == false && strict == false; 101 if (fresh) created.add( name ); 102 return consGraph( name, fresh ); 103 } 104 105 protected Graph consGraph( String name, boolean fresh ) 106 { 107 Graph p = c.getDefaultModelProperties().getGraph(); 108 return new GraphRDB( c, name, (fresh ? p : null), reificationStyle, fresh ); 109 } 110 111 116 public void removeGraph( String name ) 117 { 118 GraphRDB toDelete = (GraphRDB) openGraph( name, true ); 119 toDelete.remove(); 120 toDelete.close(); 121 created.remove( name ); 122 } 123 124 127 public boolean hasGraph( String name ) 128 { return c.containsModel( name ); } 129 130 133 public void removeAll() 134 { 135 Iterator it = CollectionFactory.createHashedSet( created ).iterator(); 136 while (it.hasNext()) removeGraph( (String ) it.next() ); 137 } 138 139 public void close() 140 { } 141 142 public ExtendedIterator listGraphs() 143 { return c.getAllModelNames() .filterDrop ( filterDEFAULT ); } 144 145 private Filter filterDEFAULT = new Filter() 146 { public boolean accept( Object x ) { return "DEFAULT".equals( x ); } }; 147 } 148 149 | Popular Tags |