1 5 6 package com.hp.hpl.jena.db.impl; 7 8 import com.hp.hpl.jena.graph.*; 9 import com.hp.hpl.jena.util.iterator.*; 10 import com.hp.hpl.jena.vocabulary.DB; 11 12 import java.text.SimpleDateFormat ; 13 import java.util.*; 14 15 32 public class DBPropDatabase extends DBProp { 33 34 37 38 public static final Node_URI dbEngineType = (Node_URI)DB.engineType.getNode(); 39 public static final Node_URI dbLayoutVersion = (Node_URI)DB.layoutVersion.getNode(); 40 public static final Node_URI dbDriverVersion = (Node_URI)DB.driverVersion.getNode(); 41 public static final Node_URI dbFormatDate = (Node_URI)DB.formatDate.getNode(); 42 public static final Node_URI dbGraph = (Node_URI)DB.graph.getNode(); 43 public static final Node_URI dbLongObjectLength = (Node_URI)DB.longObjectLength.getNode(); 44 public static final Node_URI dbIndexKeyLength = (Node_URI)DB.indexKeyLength.getNode(); 45 public static final Node_URI dbIsTransactionDb = (Node_URI)DB.isTransactionDb.getNode(); 46 public static final Node_URI dbDoCompressURI = (Node_URI)DB.doCompressURI.getNode(); 47 public static final Node_URI dbCompressURILength = (Node_URI)DB.compressURILength.getNode(); 48 public static final Node_URI dbTableNamePrefix = (Node_URI)DB.tableNamePrefix.getNode(); 49 50 public static final String dbSystemGraphName = "SystemGraph"; 51 52 protected static SimpleDateFormat dateFormat = null; 53 54 public DBPropDatabase ( SpecializedGraph g, String engineType, String driverVersion, 55 String layoutVersion, String longObjectLength, String indexKeyLength, 56 String isTransactionDb, String doCompressURI, String compressURILength, 57 String tableNamePrefix ) { 58 super(g); 59 60 if( dateFormat == null ) { 61 dateFormat = new SimpleDateFormat ("yyyyMMdd'T'HHmmss'Z'"); 63 dateFormat.setTimeZone( TimeZone.getTimeZone("GMT")); 64 } 65 66 String today = dateFormat.format( new Date()); 67 if( engineType != null ) putPropString(dbEngineType, engineType); 68 if( driverVersion != null ) putPropString(dbDriverVersion, driverVersion); 69 putPropString(dbLayoutVersion, layoutVersion); 70 putPropString(dbFormatDate, today); 71 putPropString(dbLongObjectLength, longObjectLength); 72 putPropString(dbIndexKeyLength, indexKeyLength); 73 putPropString(dbIsTransactionDb, isTransactionDb); 74 putPropString(dbDoCompressURI, doCompressURI); 75 putPropString(dbCompressURILength, compressURILength); 76 putPropString(dbTableNamePrefix, tableNamePrefix); 77 } 78 79 public DBPropDatabase( SpecializedGraph g, Node n) { 80 super(g,n); 81 } 82 83 public DBPropDatabase( SpecializedGraph g) { 84 super(g,findDBPropNode(g)); 85 } 86 87 public String getName() { return self.getURI(); } 88 public String getEngineType() { return getPropString( dbEngineType); } 89 public String getDriverVersion() { return getPropString( dbDriverVersion);} 90 public String getFormatDate() { return getPropString( dbFormatDate); } 91 public String getLayoutVersion() { return getPropString( dbLayoutVersion); } 92 public String getLongObjectLength() { return getPropString( dbLongObjectLength); } 93 public String getIndexKeyLength() { return getPropString( dbIndexKeyLength); } 94 public String getIsTransactionDb() { return getPropString( dbIsTransactionDb); } 95 public String getDoCompressURI() { return getPropString( dbDoCompressURI); } 96 public String getCompressURILength() { return getPropString( dbCompressURILength); } 97 public String getTableNamePrefix() { return getPropString( dbTableNamePrefix); } 98 99 public void addGraph( DBPropGraph g ) { 100 putPropNode( dbGraph, g.getNode() ); 101 } 102 103 public void removeGraph( DBPropGraph g ) { 104 SpecializedGraph.CompletionFlag complete = newComplete(); 105 ClosableIterator matches = graph.find( self, dbGraph, g.getNode(), complete); 106 if( matches.hasNext() ) { 107 graph.delete( (Triple)(matches.next()), complete ); 108 g.remove(); 109 matches.close(); 110 } 111 } 112 113 public ExtendedIterator getAllGraphs() { 114 return 115 graph.find( self, dbGraph, null, newComplete() ) 116 .mapWith( new MapToLSet() ); 117 } 118 119 public ExtendedIterator getAllGraphNames() { 120 return getAllGraphs() .mapWith( graphToName ); 121 } 122 123 static final Map1 graphToName = new Map1() 124 { public Object map1( Object o) { return ((DBPropGraph) o).getName(); } }; 125 126 private class MapToLSet implements Map1 { 127 public Object map1( Object o) { 128 Triple t = (Triple) o; 129 return new DBPropGraph( graph, t.getObject() ); 130 } 131 } 132 133 static Node findDBPropNode( SpecializedGraph g) { 134 ClosableIterator matches = g.find( null, dbEngineType, null, newComplete() ); 135 if( matches.hasNext()) 136 try { return ((Triple) matches.next()).getSubject(); } 137 finally { matches.close(); } 138 return null; 139 } 140 } 141 142 | Popular Tags |