1 5 6 package com.hp.hpl.jena.db; 7 8 9 import com.hp.hpl.jena.rdf.model.impl.*; 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 12 import com.hp.hpl.jena.db.impl.DBQueryHandler; 13 import com.hp.hpl.jena.enhanced.*; 14 import com.hp.hpl.jena.graph.*; 15 16 39 public class ModelRDB extends ModelCom implements Model { 40 41 protected GraphRDB m_graphRDB = null; 42 43 53 public ModelRDB( IDBConnection dbcon) throws RDFRDBException { 54 this(BuiltinPersonalities.model, new GraphRDB(dbcon, null, null, !dbcon.containsDefaultModel())); 55 } 56 57 58 71 public ModelRDB( IDBConnection dbcon, String modelID) throws RDFRDBException { 72 this(BuiltinPersonalities.model, new GraphRDB(dbcon, modelID, null, !dbcon.containsDefaultModel())); 73 } 74 75 76 88 public ModelRDB(GraphPersonality p, GraphRDB graph) throws RDFRDBException { 89 super( graph, p); 90 m_graphRDB = graph; 91 } 92 93 public ModelRDB( GraphRDB graph ) { 94 super( graph ); 95 m_graphRDB = graph; 96 } 97 98 104 public static ModelRDB open(IDBConnection dbcon) throws RDFRDBException { 105 return open(dbcon, null); 106 } 107 108 115 public static ModelRDB open(IDBConnection dbcon, String name) throws RDFRDBException { 116 GraphRDB graph = new GraphRDB(dbcon, name, null, GraphRDB.OPTIMIZE_AND_HIDE_ONLY_FULL_REIFICATIONS ,false); 117 return new ModelRDB(BuiltinPersonalities.model, graph); 118 } 119 120 126 public static ModelRDB createModel(IDBConnection dbcon) throws RDFRDBException { 127 return createModel(dbcon, null, getDefaultModelProperties(dbcon)); 128 } 129 130 150 public static ModelRDB createModel(IDBConnection dbcon, Model modelProperties) throws RDFRDBException { 151 return createModel(dbcon, null, modelProperties); 152 } 153 154 161 public static ModelRDB createModel(IDBConnection dbcon, String name) throws RDFRDBException { 162 return createModel(dbcon, name, getDefaultModelProperties(dbcon)); 163 } 164 165 187 public static ModelRDB createModel(IDBConnection dbcon, String name, Model modelProperties) throws RDFRDBException { 188 189 GraphRDB graph; 190 if( modelProperties != null ) 191 graph = new GraphRDB(dbcon, name, modelProperties.getGraph(), GraphRDB.OPTIMIZE_AND_HIDE_ONLY_FULL_REIFICATIONS ,true); 192 else 193 graph = new GraphRDB(dbcon, name, null, GraphRDB.OPTIMIZE_AND_HIDE_ONLY_FULL_REIFICATIONS, true); 194 return new ModelRDB(BuiltinPersonalities.model, graph); 195 } 196 197 218 public static ModelRDB create(IDBConnection dbcon, String layoutType, String databaseType) throws RDFRDBException { 219 dbcon.setDatabaseType(databaseType); 220 return createModel(dbcon, null, getDefaultModelProperties(dbcon)); 221 } 222 223 239 240 public static ModelRDB create(IDBConnection dbcon, String databaseType) throws RDFRDBException { 241 dbcon.setDatabaseType(databaseType); 242 return createModel(dbcon, null, getDefaultModelProperties(dbcon)); 243 } 244 245 255 256 public Model getModelProperties() { 257 Model m = ModelFactory.createDefaultModel(); 258 Graph g = m.getGraph(); 259 ExtendedIterator it = m_graphRDB.getPropertyTriples(); 260 while (it.hasNext()) g.add( (Triple) it.next()); 261 return m; 262 } 263 264 273 274 public static Model getDefaultModelProperties( IDBConnection dbcon ) { 275 return dbcon.getDefaultModelProperties(); 276 } 277 278 282 283 public static ExtendedIterator listModels(IDBConnection dbcon) throws RDFRDBException { 284 return dbcon.getAllModelNames(); 285 } 286 287 293 public void close() { 294 m_graphRDB.close(); 295 } 296 297 300 public void remove() throws RDFRDBException { 301 m_graphRDB.remove(); 302 } 303 304 307 public IDBConnection getConnection() { 308 return m_graphRDB.getConnection(); 309 } 310 311 319 public void clear() throws RDFRDBException { 320 remove(); 321 } 322 323 331 public static void deleteModel(IDBConnection dbcon, String name) throws RDFRDBException { 332 ModelRDB modelToDelete = ModelRDB.open(dbcon, name); 333 modelToDelete.remove(); 334 } 335 336 342 public Model loadAll() { 343 Model m = ModelFactory.createDefaultModel(); 344 for (StmtIterator i = this.listStatements(); i.hasNext(); ) { 345 m.add( i.nextStatement() ); 346 } 347 return m; 348 } 349 350 354 public boolean getDoDuplicateCheck() { 355 return m_graphRDB.getDoDuplicateCheck(); 356 } 357 361 public void setDoDuplicateCheck(boolean bool) { 362 m_graphRDB.setDoDuplicateCheck(bool); 363 } 364 365 369 public void setDoFastpath ( boolean val ) { 370 ((DBQueryHandler)m_graphRDB.queryHandler()).setDoFastpath(val); 371 } 372 373 377 public boolean getDoFastpath () { 378 return ((DBQueryHandler)m_graphRDB.queryHandler()).getDoFastpath(); 379 } 380 381 385 public void setQueryOnlyAsserted ( boolean opt ) { 386 ((DBQueryHandler)m_graphRDB.queryHandler()).setQueryOnlyAsserted(opt); 387 } 388 389 393 public boolean getQueryOnlyAsserted() { 394 return ((DBQueryHandler)m_graphRDB.queryHandler()).getQueryOnlyAsserted(); 395 } 396 397 401 public void setQueryOnlyReified ( boolean opt ) { 402 ((DBQueryHandler)m_graphRDB.queryHandler()).setQueryOnlyReified(opt); 403 } 404 405 409 public boolean getQueryOnlyReified() { 410 return ((DBQueryHandler)m_graphRDB.queryHandler()).getQueryOnlyReified(); 411 } 412 413 417 public void setQueryFullReified ( boolean opt ) { 418 ((DBQueryHandler)m_graphRDB.queryHandler()).setQueryFullReified(opt); 419 } 420 421 425 public boolean getQueryFullReified() { 426 return ((DBQueryHandler)m_graphRDB.queryHandler()).getQueryFullReified(); 427 } 428 429 433 public void setDoImplicitJoin ( boolean val ) { 434 ((DBQueryHandler)m_graphRDB.queryHandler()).setDoImplicitJoin(val); 435 } 436 437 438 } 439 440 469 | Popular Tags |