Browse files

added vertical partitioning layout and pluggable layout architecture

  • Loading branch information...
1 parent 29303ac commit 00745af347e6910bbddda0ff324b1c50cba016f7 vaibhavkhadilkar committed May 19, 2011
Showing with 5,800 additions and 0 deletions.
  1. +85 −0 src/main/java/com/talis/hbase/rdf/HBaseRdf.java
  2. +28 −0 src/main/java/com/talis/hbase/rdf/HBaseRdfException.java
  3. +261 −0 src/main/java/com/talis/hbase/rdf/HBaseRdfFactory.java
  4. +69 −0 src/main/java/com/talis/hbase/rdf/Store.java
  5. +74 −0 src/main/java/com/talis/hbase/rdf/StoreDesc.java
  6. +92 −0 src/main/java/com/talis/hbase/rdf/assembler/AssemblerVocab.java
  7. +29 −0 src/main/java/com/talis/hbase/rdf/assembler/CommandAssemblerException.java
  8. +52 −0 src/main/java/com/talis/hbase/rdf/assembler/DatasetStoreAssembler.java
  9. +36 −0 src/main/java/com/talis/hbase/rdf/assembler/HBaseRdfConnectionDescAssembler.java
  10. +60 −0 src/main/java/com/talis/hbase/rdf/assembler/HBaseRdfModelAssembler.java
  11. +29 −0 src/main/java/com/talis/hbase/rdf/assembler/MissingException.java
  12. +48 −0 src/main/java/com/talis/hbase/rdf/assembler/QueryAssembler.java
  13. +45 −0 src/main/java/com/talis/hbase/rdf/assembler/StoreDescAssembler.java
  14. +26 −0 src/main/java/com/talis/hbase/rdf/base/HBaseRdfStorageException.java
  15. +22 −0 src/main/java/com/talis/hbase/rdf/base/table/LocationHBaseRdf.java
  16. +120 −0 src/main/java/com/talis/hbase/rdf/connection/HBaseRdfConnection.java
  17. +63 −0 src/main/java/com/talis/hbase/rdf/connection/HBaseRdfConnectionDesc.java
  18. +81 −0 src/main/java/com/talis/hbase/rdf/connection/HBaseRdfConnectionFactory.java
  19. +55 −0 src/main/java/com/talis/hbase/rdf/graph/BulkUpdateHandlerHBaseRdf.java
  20. +104 −0 src/main/java/com/talis/hbase/rdf/graph/DatasetPrefixesHBaseRdf.java
  21. +28 −0 src/main/java/com/talis/hbase/rdf/graph/GraphHBaseRdf.java
  22. +211 −0 src/main/java/com/talis/hbase/rdf/graph/GraphHBaseRdfBase.java
  23. +71 −0 src/main/java/com/talis/hbase/rdf/graph/QueryHandlerHBaseRdf.java
  24. +196 −0 src/main/java/com/talis/hbase/rdf/graph/ReifierHBaseRdf.java
  25. +39 −0 src/main/java/com/talis/hbase/rdf/graph/TransactionHandlerHBaseRdf.java
  26. +45 −0 src/main/java/com/talis/hbase/rdf/graph/UpdateListener.java
  27. +74 −0 src/main/java/com/talis/hbase/rdf/iterator/AbstractIterator.java
  28. +63 −0 src/main/java/com/talis/hbase/rdf/iterator/IteratorOfIterators.java
  29. +37 −0 src/main/java/com/talis/hbase/rdf/layout/FmtLayout.java
  30. +300 −0 src/main/java/com/talis/hbase/rdf/layout/LoaderTuplesNodes.java
  31. +66 −0 src/main/java/com/talis/hbase/rdf/layout/QueryRunnerBase.java
  32. +83 −0 src/main/java/com/talis/hbase/rdf/layout/StoreBase.java
  33. +28 −0 src/main/java/com/talis/hbase/rdf/layout/TableDescLayouts.java
  34. +35 −0 src/main/java/com/talis/hbase/rdf/layout/TableQueryRunnerBase.java
  35. +26 −0 src/main/java/com/talis/hbase/rdf/layout/TableQueryRunnerBasics.java
  36. +111 −0 src/main/java/com/talis/hbase/rdf/layout/TupleLoaderBase.java
  37. +30 −0 src/main/java/com/talis/hbase/rdf/layout/TupleLoaderBasics.java
  38. +48 −0 src/main/java/com/talis/hbase/rdf/layout/simple/FmtLayoutSimple.java
  39. +89 −0 src/main/java/com/talis/hbase/rdf/layout/simple/HBaseRdfAllRowsWithFilterIterator.java
  40. +103 −0 src/main/java/com/talis/hbase/rdf/layout/simple/HBaseRdfSingleRowIterator.java
  41. +89 −0 src/main/java/com/talis/hbase/rdf/layout/simple/HBaseRdfSingleTableIterator.java
  42. +92 −0 src/main/java/com/talis/hbase/rdf/layout/simple/QueryRunnerSimple.java
  43. +33 −0 src/main/java/com/talis/hbase/rdf/layout/simple/StoreBaseSimple.java
  44. +33 −0 src/main/java/com/talis/hbase/rdf/layout/simple/StoreSimple.java
  45. +28 −0 src/main/java/com/talis/hbase/rdf/layout/simple/TableDescObjects.java
  46. +28 −0 src/main/java/com/talis/hbase/rdf/layout/simple/TableDescPredicates.java
  47. +34 −0 src/main/java/com/talis/hbase/rdf/layout/simple/TableDescSimple.java
  48. +39 −0 src/main/java/com/talis/hbase/rdf/layout/simple/TableDescSimpleCommon.java
  49. +28 −0 src/main/java/com/talis/hbase/rdf/layout/simple/TableDescSubjects.java
  50. +121 −0 src/main/java/com/talis/hbase/rdf/layout/simple/TupleLoaderSimple.java
  51. +49 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/FmtLayoutVerticallyPartitioned.java
  52. +90 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/HBaseRdfAllRowsWithFilterIterator.java
  53. +36 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/HBaseRdfAllTablesIterator.java
  54. +106 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/HBaseRdfSingleRowIterator.java
  55. +90 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/HBaseRdfSingleTableIterator.java
  56. +186 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/QueryRunnerVerticallyPartitioned.java
  57. +34 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/StoreBaseVerticallyPartitioned.java
  58. +33 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/StoreVerticallyPartitioned.java
  59. +38 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/TableDescVPCommon.java
  60. +28 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/TableDescVPObjects.java
  61. +28 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/TableDescVPSubjects.java
  62. +33 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/TableDescVerticallyPartitioned.java
  63. +120 −0 src/main/java/com/talis/hbase/rdf/layout/verticalpartitioning/TupleLoaderVerticallyPartitioned.java
  64. +26 −0 src/main/java/com/talis/hbase/rdf/shared/HBaseRdfInternalError.java
  65. +26 −0 src/main/java/com/talis/hbase/rdf/shared/HBaseRdfNotImplemented.java
  66. +57 −0 src/main/java/com/talis/hbase/rdf/shared/SymbolRegistry.java
  67. +57 −0 src/main/java/com/talis/hbase/rdf/store/DatasetStore.java
  68. +115 −0 src/main/java/com/talis/hbase/rdf/store/DatasetStoreHBaseRdfGraph.java
  69. +81 −0 src/main/java/com/talis/hbase/rdf/store/LayoutType.java
  70. +34 −0 src/main/java/com/talis/hbase/rdf/store/StoreConfig.java
  71. +132 −0 src/main/java/com/talis/hbase/rdf/store/StoreFactory.java
  72. +35 −0 src/main/java/com/talis/hbase/rdf/store/StoreFormatter.java
  73. +31 −0 src/main/java/com/talis/hbase/rdf/store/StoreFormatterBase.java
  74. +130 −0 src/main/java/com/talis/hbase/rdf/store/StoreInformationHolder.java
  75. +32 −0 src/main/java/com/talis/hbase/rdf/store/StoreLoader.java
  76. +29 −0 src/main/java/com/talis/hbase/rdf/store/StoreLoaderPlus.java
  77. +27 −0 src/main/java/com/talis/hbase/rdf/store/StoreMaker.java
  78. +27 −0 src/main/java/com/talis/hbase/rdf/store/StoreQueryRunner.java
  79. +58 −0 src/main/java/com/talis/hbase/rdf/store/TableDesc.java
  80. +26 −0 src/main/java/com/talis/hbase/rdf/store/TableQueryRunner.java
  81. +24 −0 src/main/java/com/talis/hbase/rdf/store/TableQueryRunnerBase.java
  82. +64 −0 src/main/java/com/talis/hbase/rdf/store/TupleGraphLoader.java
  83. +53 −0 src/main/java/com/talis/hbase/rdf/store/TupleLoader.java
  84. +50 −0 src/main/java/com/talis/hbase/rdf/store/TupleLoaderBase.java
  85. +67 −0 src/main/java/com/talis/hbase/rdf/util/HBaseUtils.java
  86. +59 −0 src/main/java/com/talis/hbase/rdf/util/Pair.java
  87. +63 −0 src/main/java/com/talis/hbase/rdf/util/StoreUtils.java
  88. +39 −0 src/main/java/com/talis/hbase/rdf/util/Vocab.java
View
85 src/main/java/com/talis/hbase/rdf/HBaseRdf.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf;
+
+import com.hp.hpl.jena.assembler.assemblers.AssemblerGroup;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
+import com.hp.hpl.jena.query.ARQ;
+import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
+import com.hp.hpl.jena.sparql.core.assembler.AssemblerUtils;
+import com.hp.hpl.jena.sparql.util.Context;
+import com.hp.hpl.jena.vocabulary.OWL;
+import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
+import com.talis.hbase.rdf.assembler.AssemblerVocab;
+
+public class HBaseRdf
+{
+ public final static String namespace = "http://rdf.hbase.talis.com/2011/hbase-rdf#" ;
+
+ public static Context getContext() { return ARQ.getContext() ; }
+
+ static { initWorker() ; }
+ public static void init() { }
+
+ /** Used by Jena assemblers for registration */
+ public static void whenRequiredByAssembler( AssemblerGroup g )
+ {
+ AssemblerUtils.init() ; // ARQ
+ AssemblerVocab.register( g ) ; // SDB
+ }
+
+ private static boolean initialized = false ;
+ private static synchronized void initWorker()
+ {
+ // Called from
+ // + StoreFactory
+ // + DatasetStore
+ // Commands call AssemblerVocab.init() ;
+
+ if ( initialized )
+ return ;
+
+ // Set this immediately in case code below causes init() to be called.
+ // (It's better if there are no dependences but ...)
+ initialized = true ;
+ }
+
+ /** RDF namespace prefix */
+ private static final String rdfPrefix = RDF.getURI() ;
+
+ /** RDFS namespace prefix */
+ private static final String rdfsPrefix = RDFS.getURI() ;
+
+ /** OWL namespace prefix */
+ private static final String owlPrefix = OWL.getURI() ;
+
+ /** XSD namespace prefix */
+ private static final String xsdPrefix = XSDDatatype.XSD + "#" ;
+
+ protected static PrefixMapping globalPrefixMap = new PrefixMappingImpl() ;
+ static
+ {
+ globalPrefixMap.setNsPrefix( "rdf", rdfPrefix ) ;
+ globalPrefixMap.setNsPrefix( "rdfs", rdfsPrefix ) ;
+ globalPrefixMap.setNsPrefix( "xsd", xsdPrefix ) ;
+ globalPrefixMap.setNsPrefix( "owl" , owlPrefix ) ;
+ globalPrefixMap.setNsPrefix( "sdb" , namespace ) ;
+ }
+ public static PrefixMapping getGlobalPrefixMapping() { return globalPrefixMap ; }
+}
View
28 src/main/java/com/talis/hbase/rdf/HBaseRdfException.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf;
+
+import com.hp.hpl.jena.shared.JenaException;
+
+@SuppressWarnings("serial")
+public class HBaseRdfException extends JenaException
+{
+ public HBaseRdfException() { super() ; }
+ public HBaseRdfException( String msg ) { super( msg ) ; }
+ public HBaseRdfException( Throwable th ) { super( th ) ; }
+ public HBaseRdfException( String msg, Throwable th ) { super( msg, th ) ; }
+}
View
261 src/main/java/com/talis/hbase/rdf/HBaseRdfFactory.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf;
+
+import org.apache.hadoop.conf.Configuration;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.shared.ReificationStyle;
+import com.hp.hpl.jena.update.GraphStore;
+import com.talis.hbase.rdf.connection.HBaseRdfConnection;
+import com.talis.hbase.rdf.connection.HBaseRdfConnectionDesc;
+import com.talis.hbase.rdf.connection.HBaseRdfConnectionFactory;
+import com.talis.hbase.rdf.graph.GraphHBaseRdfBase;
+import com.talis.hbase.rdf.store.DatasetStore;
+import com.talis.hbase.rdf.store.DatasetStoreHBaseRdfGraph;
+import com.talis.hbase.rdf.store.StoreFactory;
+
+public class HBaseRdfFactory
+{
+ // ---- Connections
+ public static HBaseRdfConnection createConnection( String configFile, boolean isAssemblerFile )
+ { return HBaseRdfConnectionFactory.create( configFile, isAssemblerFile ) ; }
+
+ public static HBaseRdfConnection createConnection( HBaseRdfConnectionDesc desc )
+ { return HBaseRdfConnectionFactory.create( desc ) ; }
+
+ public static HBaseRdfConnection createConnection( Configuration config )
+ { return HBaseRdfConnectionFactory.create( config ) ; }
+
+ public static Configuration createHBaseConfiguration( String configFile )
+ { return HBaseRdfConnectionFactory.createHBaseConfiguration( configFile ) ; }
+
+ public static Store connectStore( String configFile )
+ { return StoreFactory.create( configFile ) ; }
+
+ public static Store connectStore( StoreDesc desc )
+ { return StoreFactory.create( desc ) ; }
+
+ public static Store connectStore( HBaseRdfConnection hbaseConnection, StoreDesc desc )
+ { return StoreFactory.create( desc, hbaseConnection ) ; }
+
+ public static Store connectStore( Configuration config, StoreDesc desc )
+ {
+ HBaseRdfConnection sdb = HBaseRdfConnectionFactory.create( config ) ;
+ return StoreFactory.create( desc, sdb ) ;
+ }
+
+ // ---- Dataset
+
+ public static Dataset connectDataset( Store store )
+ { return DatasetStore.create( store ) ; }
+
+ public static Dataset connectDataset( StoreDesc desc )
+ { return DatasetStore.create( connectStore( desc ) ) ; }
+
+ public static Dataset connectDataset( HBaseRdfConnection hbaseConnection, StoreDesc desc )
+ { return DatasetStore.create( connectStore( hbaseConnection, desc ) ) ; }
+
+ public static Dataset connectDataset( Configuration config, StoreDesc desc )
+ { return DatasetStore.create( connectStore( config, desc ) ) ; }
+
+ public static Dataset connectDataset( String configFile )
+ { return DatasetStore.create( connectStore( configFile ) ) ; }
+
+ // ---- GraphStore
+
+ public static GraphStore connectGraphStore( Store store, ReificationStyle style )
+ { return new DatasetStoreHBaseRdfGraph( store, HBaseRdf.getContext().copy(), style ) ; }
+
+ public static GraphStore connectGraphStore( StoreDesc desc )
+ { return connectGraphStore( connectStore( desc ), ReificationStyle.Standard ) ; }
+
+ public static GraphStore connectGraphStore( StoreDesc desc, ReificationStyle style )
+ { return connectGraphStore( connectStore( desc ), style ) ; }
+
+ public static GraphStore connectGraphStore( HBaseRdfConnection hbaseConnection, StoreDesc desc )
+ { return connectGraphStore( connectStore( hbaseConnection, desc ), ReificationStyle.Standard ) ; }
+
+ public static GraphStore connectGraphStore( HBaseRdfConnection hbaseConnection, StoreDesc desc, ReificationStyle style )
+ { return connectGraphStore( connectStore( hbaseConnection, desc ), style ) ; }
+
+ public static GraphStore connectGraphStore( Configuration config, StoreDesc desc )
+ { return connectGraphStore( connectStore( config, desc ), ReificationStyle.Standard ) ; }
+
+ public static GraphStore connectGraphStore( Configuration config, StoreDesc desc, ReificationStyle style )
+ { return connectGraphStore( connectStore( config, desc ), style ) ; }
+
+ public static GraphStore connectGraphStore( String configFile )
+ { return connectGraphStore( connectStore( configFile ), ReificationStyle.Standard ) ; }
+
+ public static GraphStore connectGraphStore( String configFile, ReificationStyle style )
+ { return connectGraphStore( connectStore( configFile ), style ) ; }
+
+ // ---- Graph
+
+ public static Graph connectDefaultGraph( String configFile )
+ { return connectDefaultGraph( StoreFactory.create( configFile ), ReificationStyle.Standard ) ; }
+
+ public static Graph connectDefaultGraph( String configFile, ReificationStyle style )
+ { return connectDefaultGraph( StoreFactory.create( configFile ), style ) ; }
+
+ public static Graph connectDefaultGraph( StoreDesc desc )
+ { return connectDefaultGraph( StoreFactory.create( desc ), ReificationStyle.Standard ) ; }
+
+ public static Graph connectDefaultGraph( StoreDesc desc, ReificationStyle style )
+ { return connectDefaultGraph( StoreFactory.create( desc ), style ) ; }
+
+ public static Graph connectDefaultGraph( Store store, ReificationStyle style )
+ { return new GraphHBaseRdfBase( store, style ) ; }
+
+ public static Graph connectNamedGraph( String configFile, String iri )
+ { return connectNamedGraph( StoreFactory.create( configFile ), iri, ReificationStyle.Standard ) ; }
+
+ public static Graph connectNamedGraph( String configFile, String iri, ReificationStyle style )
+ { return connectNamedGraph( StoreFactory.create( configFile ), iri, style ) ; }
+
+ public static Graph connectNamedGraph( StoreDesc desc, String iri )
+ { return connectNamedGraph( StoreFactory.create( desc ), iri, ReificationStyle.Standard ) ; }
+
+ public static Graph connectNamedGraph( StoreDesc desc, String iri, ReificationStyle style )
+ { return connectNamedGraph( StoreFactory.create( desc ), iri, style ) ; }
+
+ public static Graph connectNamedGraph( Store store, String iri, ReificationStyle style )
+ { return new GraphHBaseRdfBase( store, iri, style ) ; }
+
+ public static Graph connectNamedGraph( String configFile, Node node )
+ { return connectNamedGraph( StoreFactory.create( configFile ), node, ReificationStyle.Standard ) ; }
+
+ public static Graph connectNamedGraph( String configFile, Node node, ReificationStyle style )
+ { return connectNamedGraph( StoreFactory.create( configFile ), node, style ) ; }
+
+ public static Graph connectNamedGraph( StoreDesc desc, Node node )
+ { return connectNamedGraph( StoreFactory.create( desc ), node, ReificationStyle.Standard ) ; }
+
+ public static Graph connectNamedGraph( StoreDesc desc, Node node, ReificationStyle style )
+ { return connectNamedGraph( StoreFactory.create( desc ), node, style ) ; }
+
+ public static Graph connectNamedGraph(Store store, Node node, ReificationStyle style )
+ { return new GraphHBaseRdfBase( store, node, style ) ; }
+
+
+ // ---- Model
+
+ public static Model connectDefaultModel( String configFile )
+ { return connectDefaultModel( StoreFactory.create( configFile ) ) ; }
+
+ /**
+ * Connect to the default model in a store
+ * @param desc
+ * @return Model
+ */
+ public static Model connectDefaultModel( StoreDesc desc )
+ { return connectDefaultModel( StoreFactory.create( desc ) ) ; }
+
+ /**
+ * Connect to the default model in a store
+ * @param store
+ * @return Model
+ */
+ public static Model connectDefaultModel( Store store )
+ { return createModelHBaseRdf( store, ReificationStyle.Standard ) ; }
+
+ public static Model connectDefaultModel( Store store, ReificationStyle style )
+ { return createModelHBaseRdf( store, style ) ; }
+
+ /**
+ * Connect to the named model in a store
+ * @param desc
+ * @param iri
+ * @return Model
+ */
+ public static Model connectNamedModel( StoreDesc desc, String iri )
+ { return connectNamedModel( StoreFactory.create( desc ), iri, ReificationStyle.Standard ) ; }
+
+ public static Model connectNamedModel( StoreDesc desc, String iri, ReificationStyle style )
+ { return connectNamedModel( StoreFactory.create( desc ), iri, style ) ; }
+
+ /**
+ * Connect to the named model in a store
+ * @param store
+ * @param iri
+ * @return Model
+ */
+ public static Model connectNamedModel( Store store, String iri, ReificationStyle style )
+ { return createModelHBaseRdf( store, iri, style ) ; }
+
+ /**
+ * Connect to the named model in a store
+ * @param configFile
+ * @param iri
+ * @return Model
+ */
+ public static Model connectNamedModel( String configFile, String iri )
+ { return connectNamedModel( StoreFactory.create( configFile ), iri, ReificationStyle.Standard ) ; }
+
+ public static Model connectNamedModel( String configFile, String iri, ReificationStyle style )
+ { return connectNamedModel( StoreFactory.create( configFile ), iri, style ) ; }
+
+ /**
+ * Connect to the named model in a store
+ * @param desc
+ * @param resource
+ * @return Model
+ */
+ public static Model connectNamedModel( StoreDesc desc, Resource resource )
+ { return connectNamedModel( StoreFactory.create( desc ), resource, ReificationStyle.Standard ) ; }
+
+ public static Model connectNamedModel( StoreDesc desc, Resource resource, ReificationStyle style )
+ { return connectNamedModel( StoreFactory.create( desc ), resource, style ) ; }
+
+ /**
+ * Connect to the named model in a store
+ * @param store
+ * @param resource
+ * @return Model
+ */
+ public static Model connectNamedModel( Store store, Resource resource )
+ { return createModelHBaseRdf( store, resource, ReificationStyle.Standard ) ; }
+
+ public static Model connectNamedModel( Store store, Resource resource, ReificationStyle style )
+ { return createModelHBaseRdf( store, resource, style ) ; }
+
+ /**
+ * Connect to the named model in a store
+ * @param configFile
+ * @param resource
+ * @return Model
+ */
+ public static Model connectNamedModel( String configFile, Resource resource )
+ { return connectNamedModel( StoreFactory.create( configFile ), resource ) ; }
+
+ // ---- Workers
+
+ private static Model createModelHBaseRdf( Store store, ReificationStyle style )
+ { return ModelFactory.createModelForGraph( new GraphHBaseRdfBase( store, style ) ) ; }
+
+ private static Model createModelHBaseRdf( Store store, String iri, ReificationStyle style )
+ { return ModelFactory.createModelForGraph( new GraphHBaseRdfBase( store, iri, style ) ) ; }
+
+ private static Model createModelHBaseRdf( Store store, Resource resource, ReificationStyle style )
+ { return ModelFactory.createModelForGraph( new GraphHBaseRdfBase( store, resource.asNode(), style ) ) ; }
+}
View
69 src/main/java/com/talis/hbase/rdf/Store.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf;
+
+import com.hp.hpl.jena.graph.Node;
+import com.talis.hbase.rdf.connection.HBaseRdfConnection;
+import com.talis.hbase.rdf.layout.TableDescLayouts;
+import com.talis.hbase.rdf.store.LayoutType;
+import com.talis.hbase.rdf.store.StoreConfig;
+import com.talis.hbase.rdf.store.StoreFormatter;
+import com.talis.hbase.rdf.store.StoreLoader;
+import com.talis.hbase.rdf.store.StoreQueryRunner;
+
+public interface Store
+{
+ /** Return the store name. This is necessary in HBase since a store name provides the first point of separation over
+ * all HBase tables belonging to a certain store. **/
+ public String getStoreName() ;
+
+ /** Return configuration information for a store such as the graphs held within a store. **/
+ public StoreConfig getConfig() ;
+
+ /** Return the connection to the implementing database */
+ public HBaseRdfConnection getConnection() ;
+
+ /** Return the query runner for the store **/
+ public StoreQueryRunner getQueryRunner() ;
+
+ /** Return the processor that creates the database tables */
+ public StoreFormatter getTableFormatter() ;
+
+ /** Return the (bulk) loader */
+ public StoreLoader getLoader() ;
+
+ /** Return the layout type of the store */
+ public LayoutType getLayoutType() ;
+
+ /** Stores should be closed explicitly.
+ * Some stores may require specific finalization actions (e.g. embedded databases),
+ * and some stores may be able to release system resources.
+ */
+ public void close() ;
+
+ /** Has this store been closed? **/
+ public boolean isClosed();
+
+ /** Get the size of this store **/
+ public long getSize() ;
+
+ /** Get the size of the graph corresponding to graphNode **/
+ public long getSize( Node graphNode );
+
+ /** Where the default graph is store */
+ public TableDescLayouts getTablesDesc() ;
+}
View
74 src/main/java/com/talis/hbase/rdf/StoreDesc.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf;
+
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.hp.hpl.jena.util.FileManager;
+import com.talis.hbase.rdf.assembler.AssemblerVocab;
+import com.talis.hbase.rdf.connection.HBaseRdfConnectionDesc;
+import com.talis.hbase.rdf.store.LayoutType;
+
+public class StoreDesc
+{
+ public HBaseRdfConnectionDesc connDesc = null ;
+ private LayoutType layout = null ;
+ private String name = null ;
+
+ public static StoreDesc read( String filename )
+ {
+ Model m = FileManager.get().loadModel( filename ) ;
+ return read( m ) ;
+ }
+
+ public StoreDesc( String layoutName, String name )
+ {
+ this( LayoutType.fetch( layoutName ), name ) ;
+ }
+
+ public StoreDesc( LayoutType layout, String name )
+ {
+ this.layout = layout ;
+ if( name == null ) this.name = "default" ;
+ else this.name = name ;
+ }
+
+ public String getStoreName() { return name ; }
+
+ public void setStoreName( String name ) { this.name = name ; }
+
+ public LayoutType getLayout() { return layout ; }
+
+ public void setLayout( LayoutType layout ) { this.layout = layout ; }
+
+ public static StoreDesc read( Model m )
+ {
+ // Does not mind store descriptions or dataset descriptions
+ Resource r = GraphUtils.getResourceByType( m, AssemblerVocab.StoreAssemblerType ) ;
+
+ if ( r == null )
+ throw new HBaseRdfException( "Can't find store description" ) ;
+ return read( r ) ;
+ }
+
+ public static StoreDesc read( Resource r )
+ {
+ return (StoreDesc)AssemblerBase.general.open( r ) ;
+ }
+}
View
92 src/main/java/com/talis/hbase/rdf/assembler/AssemblerVocab.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerGroup;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.talis.hbase.rdf.HBaseRdf;
+import com.talis.hbase.rdf.util.Vocab;
+
+public class AssemblerVocab
+{
+ private static final String NS = HBaseRdf.namespace ;
+
+ public static String getURI() { return NS ; }
+
+ // Types
+ public static final Resource HBaseConnectionAssemblerType = Vocab.type( NS, "HBaseConnection" ) ;
+ public static final Resource StoreAssemblerType = Vocab.type( NS, "Store" ) ;
+ public static final Resource DatasetAssemblerType = Vocab.type( NS, "DatasetStore" ) ;
+ public static final Resource ModelType = Vocab.type( NS, "Model" ) ;
+ public static final Resource GraphType = Vocab.type( NS, "Graph" ) ;
+
+ public static final Property pStore = Vocab.property( NS, "store" ) ;
+ public static final Property pDataset = Vocab.property( NS, "dataset" ) ;
+ public static final Property pGraphData = Vocab.property( NS, "graph" ) ;
+ public static final Property pNamedGraph1 = Vocab.property( NS, "graphName" ) ;
+ public static final Property pNamedGraph2 = Vocab.property( NS, "namedGraph" ) ;
+
+ // ---- Store
+ public static final Property pName = Vocab.property( NS, "name" ) ;
+ public static final Property pLayout = Vocab.property( NS, "layout" ) ;
+ public static final Property pConnection = Vocab.property( NS, "connection" ) ;
+
+ // ---- Connection
+ public static final Property pHBaseRdfConfiguration = Vocab.property( NS, "configuration" ) ;
+
+ // ---- Query
+ public static final Resource QueryAssemblerType = Vocab.type( NS, "Query" ) ;
+
+ public static final Property pQuery = Vocab.property( NS, "query" ) ;
+ public static final Property pQueryFile = Vocab.property( NS, "queryFile" ) ;
+ public static final Property pQueryString = Vocab.property( NS, "queryString" ) ;
+
+ public static final Property pOutputFormat = Vocab.property( NS, "outputFormat" ) ;
+
+ private static boolean initialized = false ;
+
+ static { init() ; }
+
+ static public void init()
+ {
+ if ( initialized )
+ return ;
+ register( Assembler.general ) ;
+ initialized = true ;
+ }
+
+ static public void register( AssemblerGroup g )
+ {
+ // Wire in the extension assemblers (extensions relative to the Jena assembler framework)
+ //assemblerClass(CommandAssemblerType, new CommandAssembler()) ;
+ assemblerClass( g, QueryAssemblerType, new QueryAssembler() ) ;
+ assemblerClass( g, HBaseConnectionAssemblerType, new HBaseRdfConnectionDescAssembler() ) ;
+ assemblerClass( g, StoreAssemblerType, new StoreDescAssembler() ) ;
+ assemblerClass( g, DatasetAssemblerType, new DatasetStoreAssembler() ) ;
+ assemblerClass( g, ModelType, new HBaseRdfModelAssembler() ) ;
+ assemblerClass( g, GraphType, new HBaseRdfModelAssembler() ) ;
+ }
+
+ private static void assemblerClass( AssemblerGroup g, Resource r, Assembler a )
+ {
+ if ( g == null )
+ g = Assembler.general ;
+ g.implementWith( r, a ) ;
+ }
+}
View
29 src/main/java/com/talis/hbase/rdf/assembler/CommandAssemblerException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.exceptions.AssemblerException;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+@SuppressWarnings("serial")
+public class CommandAssemblerException extends AssemblerException
+{
+ public CommandAssemblerException( Resource cmd, String string )
+ {
+ super( cmd, string ) ;
+ }
+}
View
52 src/main/java/com/talis/hbase/rdf/assembler/DatasetStoreAssembler.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.Mode;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.talis.hbase.rdf.HBaseRdfFactory;
+import com.talis.hbase.rdf.StoreDesc;
+
+public class DatasetStoreAssembler extends AssemblerBase implements Assembler
+{
+ static StoreDescAssembler storeAssem = new StoreDescAssembler() ;
+
+ @Override
+ public Dataset open( Assembler a, Resource root, Mode mode )
+ {
+ StoreDesc desc = openStore( a, root, mode ) ;
+ Dataset ds = HBaseRdfFactory.connectDataset( desc ) ;
+ return ds ;
+ }
+
+ /** Get the StoreDesc for this dataset */
+ public StoreDesc openStore( Assembler a, Resource root, Mode mode )
+ {
+ Resource s = storeResource( root ) ;
+ StoreDesc desc = storeAssem.open( a, s, mode ) ;
+ return desc ;
+ }
+
+ static Resource storeResource( Resource dsAssem )
+ {
+ return GraphUtils.getResourceValue( dsAssem, AssemblerVocab.pStore ) ;
+ }
+}
View
36 src/main/java/com/talis/hbase/rdf/assembler/HBaseRdfConnectionDescAssembler.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.Mode;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.talis.hbase.rdf.connection.HBaseRdfConnectionDesc;
+
+public class HBaseRdfConnectionDescAssembler extends AssemblerBase implements Assembler
+{
+ @Override
+ public HBaseRdfConnectionDesc open( Assembler a, Resource root, Mode mode )
+ {
+ HBaseRdfConnectionDesc sDesc = HBaseRdfConnectionDesc.blank() ;
+
+ sDesc.setConfig( GraphUtils.getStringValue( root, AssemblerVocab.pHBaseRdfConfiguration ) ) ;
+ return sDesc ;
+ }
+}
View
60 src/main/java/com/talis/hbase/rdf/assembler/HBaseRdfModelAssembler.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.Mode;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.talis.hbase.rdf.HBaseRdfFactory;
+import com.talis.hbase.rdf.StoreDesc;
+
+public class HBaseRdfModelAssembler extends AssemblerBase implements Assembler
+{
+ DatasetStoreAssembler datasetAssem = new DatasetStoreAssembler() ;
+
+ @Override
+ public Model open(Assembler a, Resource root, Mode mode)
+ {
+ // Make a model.
+ // [] rdf:type hbaserdf:Model ;
+ // hbaserdf:dataset <dataset> ;
+ // hbaserdf:graphName <someURI> .
+
+ // A model (graph) is a (dataset, name) pair where the name can be absent
+ // meaning the default graph of the dataset.
+
+ Resource dataset = GraphUtils.getResourceValue( root, AssemblerVocab.pDataset ) ;
+ if ( dataset == null )
+ throw new MissingException( root, "No dataset for model or graph" ) ;
+ StoreDesc storeDesc = datasetAssem.openStore( a, dataset, mode ) ;
+
+ // Attempt to find a graph name - may be absent.
+ // Two names : "namedGraph" and "graphName"
+ String x = GraphUtils.getAsStringValue( root, AssemblerVocab.pNamedGraph1 ) ;
+ if ( x == null )
+ x = GraphUtils.getAsStringValue( root, AssemblerVocab.pNamedGraph2 ) ;
+
+ // No name - default model.
+ if ( x == null )
+ return HBaseRdfFactory.connectDefaultModel( storeDesc ) ;
+ else
+ return HBaseRdfFactory.connectNamedModel( storeDesc, x ) ;
+ }
+}
View
29 src/main/java/com/talis/hbase/rdf/assembler/MissingException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.exceptions.AssemblerException;
+import com.hp.hpl.jena.rdf.model.Resource;
+
+@SuppressWarnings("serial")
+public class MissingException extends AssemblerException
+{
+ public MissingException( Resource type, String string )
+ {
+ super( type, string ) ;
+ }
+}
View
48 src/main/java/com/talis/hbase/rdf/assembler/QueryAssembler.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.Mode;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.FmtUtils;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.hp.hpl.jena.util.FileManager;
+
+public class QueryAssembler extends AssemblerBase implements Assembler
+{
+ @Override
+ public Object open( Assembler a, Resource cmd, Mode mode )
+ {
+ if ( cmd.hasProperty( AssemblerVocab.pQueryFile ) && cmd.hasProperty( AssemblerVocab.pQueryString ) )
+ throw new CommandAssemblerException( cmd, "Both " + FmtUtils.stringForResource( AssemblerVocab.pQueryString ) + " and " + FmtUtils.stringForResource( AssemblerVocab.pQueryFile ) + " present" ) ;
+ if ( !cmd.hasProperty( AssemblerVocab.pQueryFile ) && ! cmd.hasProperty( AssemblerVocab.pQueryString ) )
+ throw new CommandAssemblerException( cmd, "No queryString or queryFile present" ) ;
+
+ String queryString = GraphUtils.getStringValue( cmd, AssemblerVocab.pQueryString ) ;
+ if ( queryString == null )
+ {
+ String filename = GraphUtils.getStringValue( cmd, AssemblerVocab.pQueryFile ) ;
+ queryString = FileManager.get().readWholeFileAsUTF8( filename ) ;
+ }
+ // Base??
+ // Convert to another exception?
+ return QueryFactory.create( queryString ) ;
+ }
+}
View
45 src/main/java/com/talis/hbase/rdf/assembler/StoreDescAssembler.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.assembler;
+
+import com.hp.hpl.jena.assembler.Assembler;
+import com.hp.hpl.jena.assembler.Mode;
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.talis.hbase.rdf.StoreDesc;
+import com.talis.hbase.rdf.connection.HBaseRdfConnectionDesc;
+
+public class StoreDescAssembler extends AssemblerBase implements Assembler
+{
+ @Override
+ public StoreDesc open( Assembler a, Resource root, Mode mode )
+ {
+ HBaseRdfConnectionDesc hbaseConnDesc = null ;
+ Resource c = GraphUtils.getResourceValue( root, AssemblerVocab.pConnection ) ;
+ if ( c != null )
+ hbaseConnDesc = (HBaseRdfConnectionDesc)a.open( c ) ;
+
+ String layoutName = GraphUtils.getStringValue( root, AssemblerVocab.pLayout ) ;
+ String name = GraphUtils.getStringValue( root, AssemblerVocab.pName ) ;
+
+ StoreDesc storeDesc = new StoreDesc( layoutName, name ) ;
+ storeDesc.connDesc = hbaseConnDesc ;
+
+ return storeDesc;
+ }
+}
View
26 src/main/java/com/talis/hbase/rdf/base/HBaseRdfStorageException.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.base;
+
+@SuppressWarnings("serial")
+public class HBaseRdfStorageException extends RuntimeException
+{
+ public HBaseRdfStorageException() { super() ; }
+ public HBaseRdfStorageException( String msg ) { super( msg ) ; }
+ public HBaseRdfStorageException( Throwable th ) { super( th ) ; }
+ public HBaseRdfStorageException( String msg, Throwable th ) { super( msg, th ) ; }
+}
View
22 src/main/java/com/talis/hbase/rdf/base/table/LocationHBaseRdf.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.base.table;
+
+public class LocationHBaseRdf
+{
+
+}
View
120 src/main/java/com/talis/hbase/rdf/connection/HBaseRdfConnection.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.connection;
+
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HBaseRdfConnection
+{
+ static private Logger log = LoggerFactory.getLogger( HBaseRdfConnection.class ) ;
+
+ private Configuration config = null ;
+
+ private HBaseAdmin admin = null ;
+
+ public HBaseRdfConnection( String configFile )
+ {
+ this.config = HBaseRdfConnectionFactory.createHBaseConfiguration( configFile ) ;
+ this.admin = HBaseRdfConnectionFactory.createHBaseAdmin( config ) ;
+ }
+
+ public HBaseRdfConnection( Configuration config )
+ {
+ this.config = config ;
+ this.admin = HBaseRdfConnectionFactory.createHBaseAdmin( config ) ;
+ }
+
+ public Configuration getConfiguration() { return config ; }
+
+ public static HBaseRdfConnection none() { return new HBaseRdfConnection( "none" ) ; }
+
+ public boolean hasAdminConnection() { return admin != null ; }
+
+ public HBaseAdmin getAdmin() { return admin ; }
+
+ public HTable openTable( String tableName )
+ {
+ HTable table = null ;
+ try
+ {
+ admin.enableTable( tableName ) ;
+ table = new HTable( config, tableName ) ;
+ }
+ catch( Exception e ) { exception( "openTable", e, tableName ) ; }
+ return table ;
+ }
+
+ public void deleteTable( String tableName )
+ {
+ try
+ {
+ if( admin.tableExists( tableName ) )
+ {
+ admin.disableTable( tableName ) ;
+ admin.deleteTable( tableName ) ;
+ }
+ }
+ catch( Exception e ) { exception( "deleteTable", e, tableName ) ; }
+ }
+
+ public HTable createTable( HTableDescriptor tableDesc )
+ {
+ HTable table = null ;
+ try
+ {
+ admin.createTable( tableDesc ) ;
+ admin.enableTable( tableDesc.getNameAsString() ) ;
+ table = new HTable( config, tableDesc.getNameAsString() ) ;
+ }
+ catch( Exception e ) { exception( "createTable", e, tableDesc.getNameAsString() ) ; }
+ return table ;
+ }
+
+ public HTable createTable( String tableName, List<String> columnNames )
+ {
+ HTable table = null ;
+ try
+ {
+ HTableDescriptor tableDescriptor = new HTableDescriptor( tableName ) ;
+ admin.createTable( tableDescriptor ) ;
+ admin.disableTable( tableName ) ;
+
+ for( int i = 0; i < columnNames.size(); i++ )
+ {
+ HColumnDescriptor columnDescriptor = new HColumnDescriptor( columnNames.get( i ) ) ;
+ admin.addColumn( tableName, columnDescriptor ) ;
+ }
+ admin.enableTable( tableName ) ;
+ table = new HTable( config, tableName ) ;
+ }
+ catch( Exception e ) { exception( "createTable", e, tableName ); }
+ return table ;
+ }
+
+ private void exception( String who, Exception e, String tableName )
+ {
+ log.info( who + ": Exception \n " + e.getMessage() + " \n " + tableName ) ;
+ }
+}
View
63 src/main/java/com/talis/hbase/rdf/connection/HBaseRdfConnectionDesc.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.connection;
+
+import com.hp.hpl.jena.assembler.assemblers.AssemblerBase;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.sparql.util.graph.GraphUtils;
+import com.hp.hpl.jena.util.FileManager;
+import com.talis.hbase.rdf.HBaseRdfException;
+import com.talis.hbase.rdf.assembler.AssemblerVocab;
+
+public class HBaseRdfConnectionDesc
+{
+ private String config = null ;
+
+ public static HBaseRdfConnectionDesc blank()
+ { return new HBaseRdfConnectionDesc() ; }
+
+ public static HBaseRdfConnectionDesc none()
+ {
+ HBaseRdfConnectionDesc x = new HBaseRdfConnectionDesc() ;
+ x.config = "none" ;
+ return x ;
+ }
+
+ private HBaseRdfConnectionDesc() {}
+
+ public static HBaseRdfConnectionDesc read( String filename )
+ {
+ Model m = FileManager.get().loadModel( filename ) ;
+ return worker( m ) ;
+ }
+
+ public static HBaseRdfConnectionDesc read( Model m ) { return worker( m ) ; }
+
+ private static HBaseRdfConnectionDesc worker( Model m )
+ {
+ Resource r = GraphUtils.getResourceByType( m, AssemblerVocab.HBaseConnectionAssemblerType ) ;
+ if ( r == null )
+ throw new HBaseRdfException( "Can't find connection description" ) ;
+ HBaseRdfConnectionDesc desc = ( HBaseRdfConnectionDesc )AssemblerBase.general.open( r ) ;
+ return desc ;
+ }
+
+ public void setConfig( String config ) { this.config = config; }
+
+ public String getConfig() { return config; }
+}
View
81 src/main/java/com/talis/hbase/rdf/connection/HBaseRdfConnectionFactory.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.connection;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+
+import com.talis.hbase.rdf.HBaseRdfException;
+
+public class HBaseRdfConnectionFactory
+{
+ public static HBaseRdfConnection create( HBaseRdfConnectionDesc desc ) { return worker( desc ) ; }
+
+ public static HBaseRdfConnection create( String configFile, boolean isAssemblerFile )
+ {
+ if( isAssemblerFile )
+ {
+ HBaseRdfConnectionDesc desc = HBaseRdfConnectionDesc.read( configFile ) ;
+ return create( desc ) ;
+ }
+ else
+ return new HBaseRdfConnection( configFile ) ;
+ }
+
+ public static HBaseRdfConnection create( Configuration config ) { return new HBaseRdfConnection( config ) ; }
+
+ private static HBaseRdfConnection worker( HBaseRdfConnectionDesc desc )
+ { return makeHBaseConnection( desc ) ; }
+
+ private static HBaseRdfConnection makeHBaseConnection( HBaseRdfConnectionDesc desc )
+ {
+ HBaseRdfConnection c = new HBaseRdfConnection( createHBaseConfiguration( desc.getConfig() ) ) ;
+ return c ;
+ }
+
+ public static HBaseAdmin createHBaseAdmin( HBaseRdfConnectionDesc desc )
+ {
+ Configuration config = HBaseConfiguration.create() ;
+ config.addResource( desc.getConfig() ) ;
+ try { return new HBaseAdmin( config ) ; }
+ catch ( Exception e ) { throw new HBaseRdfException( "HBase exception while creating admin" ) ; }
+ }
+
+ public static HBaseAdmin createHBaseAdmin( String configFile )
+ {
+ Configuration config = HBaseConfiguration.create() ;
+ config.addResource( new Path( configFile ) ) ;
+ try { return new HBaseAdmin( config ) ; }
+ catch ( Exception e ) { throw new HBaseRdfException( "HBase exception while creating admin" ) ; }
+ }
+
+ public static HBaseAdmin createHBaseAdmin( Configuration config )
+ {
+ try { return new HBaseAdmin( config ) ; }
+ catch ( Exception e ) { throw new HBaseRdfException( "HBase exception while creating admin" ) ; }
+ }
+
+ public static Configuration createHBaseConfiguration( String configFile )
+ {
+ Configuration config = HBaseConfiguration.create() ;
+ config.addResource( new Path( configFile ) ) ;
+ return config ;
+ }
+}
View
55 src/main/java/com/talis/hbase/rdf/graph/BulkUpdateHandlerHBaseRdf.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import com.hp.hpl.jena.graph.BulkUpdateHandler;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.GraphEvents;
+import com.hp.hpl.jena.graph.GraphUtil;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+
+public class BulkUpdateHandlerHBaseRdf extends SimpleBulkUpdateHandler implements BulkUpdateHandler
+{
+ public BulkUpdateHandlerHBaseRdf( GraphHBaseRdfBase graph )
+ { super( graph ) ; }
+
+ public void removeAll()
+ { removeAll( graph ); notifyRemoveAll() ; }
+
+ protected void notifyRemoveAll()
+ { manager.notifyEvent( graph, GraphEvents.removeAll ) ; }
+
+ public void remove( Node s, Node p, Node o )
+ { removeAll( graph, s, p, o ) ; manager.notifyEvent( graph, GraphEvents.remove( s, p, o ) ) ; }
+
+ public static void removeAll( Graph g, Node s, Node p, Node o )
+ {
+ ExtendedIterator<Triple> it = g.find( s, p, o ) ;
+ try { while ( it.hasNext()) { g.delete( it.next() ) ; } }
+ finally { it.close() ; }
+ }
+
+ public static void removeAll( Graph g )
+ {
+ ExtendedIterator<Triple> it = GraphUtil.findAll( g ) ;
+ try { while ( it.hasNext() ) { g.delete( it.next() ) ; } }
+ finally { it.close() ; }
+ }
+}
View
104 src/main/java/com/talis/hbase/rdf/graph/DatasetPrefixesHBaseRdf.java
@@ -0,0 +1,104 @@
+/*
+* Copyright © 2010 Talis Systems Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package com.talis.hbase.rdf.graph;
+
+import java.util.Map;
+import java.util.Set;
+
+import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
+import com.hp.hpl.jena.sparql.core.DatasetPrefixStorage;
+
+public class DatasetPrefixesHBaseRdf implements DatasetPrefixStorage
+{
+ static final String unamedGraphURI = "" ;
+
+ @Override
+ public PrefixMapping getPrefixMapping()
+ { return getPrefixMapping( unamedGraphURI ) ; }
+
+ @Override
+ public PrefixMapping getPrefixMapping( String graphName )
+ {
+ //TODO: Uses default prefix mapping implementation
+ return new PrefixMappingImpl() ;
+ }
+
+ @Override
+ public Set<String> graphNames()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void insertPrefix( String graphName, String prefix, String uri )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void loadPrefixMapping( String graphName, PrefixMapping pmap )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public String readByURI( String graphName, String uriStr )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String readPrefix( String graphName, String prefix )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<String, String> readPrefixMap( String graphName )
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void removeFromPrefixMap( String graphName, String prefix, String uri )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void close()
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void sync()
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void sync( boolean force )
+ {
+ // TODO Auto-generated method stub
+ }
+}
View
28 src/main/java/com/talis/hbase/rdf/graph/GraphHBaseRdf.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import org.openjena.atlas.lib.Closeable;
+import org.openjena.atlas.lib.Sync;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.sparql.engine.optimizer.reorder.Reorderable;
+
+public interface GraphHBaseRdf extends Graph, Closeable, Sync, Reorderable
+{
+ public void clear() ;
+}
View
211 src/main/java/com/talis/hbase/rdf/graph/GraphHBaseRdfBase.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import java.util.Iterator;
+
+import com.hp.hpl.jena.graph.BulkUpdateHandler;
+import com.hp.hpl.jena.graph.Capabilities;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Reifier;
+import com.hp.hpl.jena.graph.TransactionHandler;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.graph.TripleMatch;
+import com.hp.hpl.jena.graph.query.QueryHandler;
+import com.hp.hpl.jena.shared.Lock;
+import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.shared.ReificationStyle;
+import com.hp.hpl.jena.shared.impl.JenaParameters;
+import com.hp.hpl.jena.sparql.core.DatasetPrefixStorage;
+import com.hp.hpl.jena.sparql.core.Quad;
+import com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderTransformation;
+import com.hp.hpl.jena.sparql.graph.GraphBase2;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.talis.hbase.rdf.HBaseRdf;
+import com.talis.hbase.rdf.Store;
+import com.talis.hbase.rdf.store.DatasetStoreHBaseRdfGraph;
+import com.talis.hbase.rdf.store.StoreLoaderPlus;
+
+/**
+ * A graph implementation for HBase.
+ */
+public class GraphHBaseRdfBase extends GraphBase2 implements GraphHBaseRdf
+{
+ //private final QueryHandlerHBaseRdf queryHandler = new QueryHandlerHBaseRdf( this ) ;
+ private final TransactionHandler transactionHandler = new TransactionHandlerHBaseRdf( this ) ;
+ //private final BulkUpdateHandler bulkUpdateHandler = new BulkUpdateHandlerHBaseRdf( this ) ;
+ //private final Reifier reifier ;
+ protected final DatasetStoreHBaseRdfGraph dataset ;
+ protected final Node graphNode ;
+ protected Store store = null ;
+ private final DatasetPrefixStorage prefixes ;
+ protected int inBulkUpdate = 0 ;
+
+ public GraphHBaseRdfBase( Store store, String uri, ReificationStyle style )
+ {
+ this( store, Node.createURI( uri ), style ) ;
+ }
+
+ public GraphHBaseRdfBase( Store store, ReificationStyle style )
+ {
+ this( store, (Node)null, style ) ;
+ }
+
+ public GraphHBaseRdfBase( Store store, Node graphNode, ReificationStyle style )
+ {
+ //Add this graph to the current store
+ if( graphNode != null )
+ store.getConfig().addGraphInfoToStore( graphNode, this ) ;
+
+ if ( graphNode == null )
+ graphNode = Quad.defaultGraphNodeGenerated ;
+
+ this.graphNode = graphNode ;
+ this.store = store ;
+
+ this.prefixes = new DatasetPrefixesHBaseRdf();
+ this.reifier = new ReifierHBaseRdf( this, style ) ;
+
+ this.queryHandler = new QueryHandlerHBaseRdf( this ) ;
+ this.bulkHandler = new BulkUpdateHandlerHBaseRdf( this ) ;
+
+ //Use the deterministic blank node generation algorithm
+ JenaParameters.disableBNodeUIDGeneration = true ;
+
+ // Avoid looping here : DatasetStoreGraph can make GraphSDB's
+ dataset = new DatasetStoreHBaseRdfGraph( store, this, HBaseRdf.getContext().copy(), style ) ;
+
+ if( graphNode.hasURI( "urn:x-arq:UnionGraph" ) )
+ addTriplesToSpecializedGraph() ;
+ }
+
+ private void addTriplesToSpecializedGraph()
+ {
+ Iterator<Graph> graphs = store.getConfig().listGraphs() ;
+ while( graphs.hasNext() ) getBulkUpdateHandler().add( graphs.next() ) ;
+ }
+
+ public void clear() { store.getTableFormatter().truncate() ; }
+
+ /**
+ * @see com.hp.hpl.jena.graph.GraphAdd#add( com.hp.hpl.jena.graph.Triple )
+ */
+ @Override
+ public void performAdd( Triple triple )
+ {
+ //TODO: Don't know if we should be doing this, i.e. differentiating between reification styles.
+ if( getReifier().getStyle().conceals() && getReifier().getStyle().intercepts() ) return ;
+
+ if ( inBulkUpdate == 0 ) store.getLoader().startBulkUpdate() ;
+
+ if ( Quad.isQuadDefaultGraphGenerated( graphNode ) )
+ store.getLoader().addTriple(triple) ;
+ else
+ {
+ // XXX
+ StoreLoaderPlus x = (StoreLoaderPlus)store.getLoader() ;
+ x.addQuad( graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject() ) ;
+ }
+ if ( inBulkUpdate == 0 ) store.getLoader().finishBulkUpdate() ;
+ }
+
+ @Override
+ public void performDelete( Triple triple )
+ {
+ if (inBulkUpdate == 0) store.getLoader().startBulkUpdate();
+ if ( Quad.isQuadDefaultGraphGenerated( graphNode ) )
+ store.getLoader().deleteTriple( triple ) ;
+ else
+ {
+ // XXX
+ StoreLoaderPlus x = (StoreLoaderPlus)store.getLoader() ;
+ x.deleteQuad( graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject() ) ;
+ }
+ if (inBulkUpdate == 0) store.getLoader().finishBulkUpdate();
+ }
+
+ public void startBulkUpdate() { inBulkUpdate += 1 ; if (inBulkUpdate == 1) store.getLoader().startBulkUpdate() ; }
+ public void finishBulkUpdate() { inBulkUpdate -= 1 ; if (inBulkUpdate == 0) store.getLoader().finishBulkUpdate( ) ; }
+
+ /**
+ * @see com.hp.hpl.jena.graph.Graph#find( com.hp.hpl.jena.graph.Node, com.hp.hpl.jena.graph.Node, com.hp.hpl.jena.graph.Node )
+ */
+ @Override
+ protected ExtendedIterator<Triple> graphBaseFind( TripleMatch tm ) { return store.getQueryRunner().storeFind( tm, graphNode ) ; }
+
+ @Override
+ public Capabilities getCapabilities()
+ {
+ if ( capabilities == null )
+ capabilities = new Capabilities()
+ {
+ public boolean sizeAccurate() { return true ; }
+ public boolean addAllowed() { return true ; }
+ public boolean addAllowed( boolean every ) { return true ; }
+ public boolean deleteAllowed() { return true ; }
+ public boolean deleteAllowed( boolean every ) { return true ; }
+ public boolean canBeEmpty() { return true ; }
+ public boolean iteratorRemoveAllowed() { return false ; }
+ public boolean findContractSafe() { return true ; }
+ public boolean handlesLiteralTyping() { return false ; }
+ } ;
+ return super.getCapabilities() ;
+ }
+
+ //@Override
+ public final Node getGraphNode() { return graphNode ; }
+
+ //@Override
+ public final DatasetStoreHBaseRdfGraph getDataset() { return dataset ; }
+
+ //@Override
+ public Lock getLock() { return dataset.getLock() ; }
+
+ @Override
+ public BulkUpdateHandler getBulkUpdateHandler() { return bulkHandler ; }
+
+ @Override
+ public QueryHandler queryHandler() { return queryHandler ; }
+
+ @Override
+ public TransactionHandler getTransactionHandler() { return transactionHandler ; }
+
+ @Override
+ protected PrefixMapping createPrefixMapping() { return prefixes.getPrefixMapping() ; }
+
+ public Reifier getReifier() { return reifier ; }
+
+ @Override
+ public void sync()
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void sync( boolean arg0 )
+ {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public ReorderTransformation getReorderTransform()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
View
71 src/main/java/com/talis/hbase/rdf/graph/QueryHandlerHBaseRdf.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import java.util.Set;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.graph.query.QueryHandler;
+import com.hp.hpl.jena.graph.query.SimpleQueryHandler;
+import com.hp.hpl.jena.util.CollectionFactory;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+
+public class QueryHandlerHBaseRdf extends SimpleQueryHandler implements QueryHandler
+{
+ Graph graph ;
+
+ public QueryHandlerHBaseRdf( GraphHBaseRdf graph ) { super( graph ) ; this.graph = graph ; }
+
+ @Override
+ public boolean containsNode( Node n ) { return super.containsNode( n ) ; }
+
+ @Override
+ public ExtendedIterator<Node> subjectsFor( Node p, Node o ) { return subjectsFor( graph, p, o ); }
+
+ public static ExtendedIterator<Node> subjectsFor( Graph g, Node p, Node o )
+ {
+ Set<Node> subjects = CollectionFactory.createHashedSet() ;
+ ExtendedIterator<Triple> iter = g.find( Node.ANY, p, o ) ;
+ while( iter.hasNext() ) subjects.add( iter.next().getSubject() ) ;
+ return WrappedIterator.createNoRemove( subjects.iterator() ) ;
+ }
+
+ @Override
+ public ExtendedIterator<Node> predicatesFor( Node s, Node o ) { return predicatesFor( graph, s, o ) ; }
+
+ public static ExtendedIterator<Node> predicatesFor( Graph g, Node s, Node o )
+ {
+ Set<Node> predicates = CollectionFactory.createHashedSet() ;
+ ExtendedIterator<Triple> iter = g.find( s, Node.ANY, o ) ;
+ while( iter.hasNext() ) predicates.add( iter.next().getPredicate() ) ;
+ return WrappedIterator.createNoRemove( predicates.iterator() ) ;
+ }
+
+ @Override
+ public ExtendedIterator<Node> objectsFor( Node s, Node p ) { return objectsFor( graph, s, p ) ; }
+
+ public static ExtendedIterator<Node> objectsFor( Graph g, Node s, Node p )
+ {
+ Set<Node> objects = CollectionFactory.createHashedSet() ;
+ ExtendedIterator<Triple> iter = g.find( s, p, Node.ANY ) ;
+ while( iter.hasNext() ) objects.add( iter.next().getObject() ) ;
+ return WrappedIterator.createNoRemove( objects.iterator() ) ;
+ }
+}
View
196 src/main/java/com/talis/hbase/rdf/graph/ReifierHBaseRdf.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Reifier;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.graph.TripleMatch;
+import com.hp.hpl.jena.shared.AlreadyReifiedException;
+import com.hp.hpl.jena.shared.CannotReifyException;
+import com.hp.hpl.jena.shared.ReificationStyle;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.WrappedIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+public class ReifierHBaseRdf implements Reifier
+{
+ private final GraphHBaseRdf parent ;
+ private ReificationStyle style ;
+ private final boolean concealing ;
+
+ public ReifierHBaseRdf( GraphHBaseRdf graph ) { this( graph, ReificationStyle.Standard ) ; }
+
+ public ReifierHBaseRdf( GraphHBaseRdf graph, ReificationStyle style )
+ { this.parent = graph; this.style = style; this.concealing = style.conceals() ; }
+
+ @Override
+ public Triple getTriple( Node n )
+ {
+ Node sub = null, pred = null, obj = null ; boolean isStatementFound = false ;
+ ExtendedIterator<Triple> eit = parent.find( n, Node.ANY, Node.ANY ) ;
+ while( eit.hasNext() )
+ {
+ Triple t = eit.next() ;
+ if( isStatementFound && sub != null && pred != null && obj != null ) { isStatementFound = false ; sub = null ; pred = null ; obj = null ; }
+ if( t.predicateMatches( RDF.subject.asNode() ) ) { if( sub == null ) sub = t.getObject() ; else return null ; }
+ else if( t.predicateMatches( RDF.predicate.asNode() ) ) { if( pred == null ) pred = t.getObject() ; else return null ; }
+ else if( t.predicateMatches( RDF.object.asNode() ) ) { if( obj == null ) obj = t.getObject() ; else return null ; }
+ else if( t.predicateMatches( RDF.type.asNode() ) && t.objectMatches( RDF.Statement.asNode() ) ) isStatementFound = true ;
+ }
+ Triple tr = null ;
+ if( isStatementFound && sub != null && pred != null && obj != null ) tr = Triple.create( sub, pred, obj ) ;
+ return tr ;
+ }
+
+ @Override
+ public ExtendedIterator<Node> allNodes()
+ {
+ ExtendedIterator<Triple> eit = parent.find( Node.ANY, RDF.type.asNode(), RDF.Statement.asNode() ) ;
+ Set<Node> nodes = new HashSet<Node>() ;
+ while( eit.hasNext() ) nodes.add( eit.next().getSubject() ) ;
+ return WrappedIterator.create( nodes.iterator() ) ;
+ }
+
+ @Override
+ public ExtendedIterator<Node> allNodes( Triple t )
+ {
+ Set<Node> nodes = new HashSet<Node>() ;
+ ExtendedIterator<Triple> eit = parent.find( Node.ANY, RDF.type.asNode(), RDF.Statement.asNode() ) ;
+ while( eit.hasNext() ) nodes.add( eit.next().getSubject() ) ;
+
+ Set<Node> subNodes = new HashSet<Node>() ;
+ ExtendedIterator<Triple> subEit = parent.find( Node.ANY, RDF.subject.asNode(), t.getSubject() ) ;
+ while( subEit.hasNext() ) subNodes.add( subEit.next().getSubject() ) ;
+ nodes.retainAll( subNodes ) ; subNodes = null ;
+
+ Set<Node> predNodes = new HashSet<Node>() ;
+ ExtendedIterator<Triple> predEit = parent.find( Node.ANY, RDF.predicate.asNode(), t.getPredicate() ) ;
+ while( predEit.hasNext() ) predNodes.add( predEit.next().getSubject() ) ;
+ nodes.retainAll( predNodes ) ; predNodes = null ;
+
+ Set<Node> objNodes = new HashSet<Node>() ;
+ ExtendedIterator<Triple> objEit = parent.find( Node.ANY, RDF.object.asNode(), t.getObject() ) ;
+ while( objEit.hasNext() ) objNodes.add( objEit.next().getSubject() ) ;
+ nodes.retainAll( objNodes ) ; objNodes = null ;
+
+ return WrappedIterator.create( nodes.iterator() ) ;
+ }
+
+ @Override
+ public void close() { }
+
+ @Override
+ public ExtendedIterator<Triple> find( TripleMatch tm )
+ { return matchesReification( tm ) ? parent.find( tm ) : Triple.None ; }
+
+ @Override
+ public ExtendedIterator<Triple> findEither( TripleMatch tm, boolean showHidden )
+ { return showHidden == concealing ? find( tm ) : Triple.None ; }
+
+ @Override
+ public ExtendedIterator<Triple> findExposed( TripleMatch tm )
+ { return findEither( tm, false ) ; }
+
+ @Override
+ public Graph getParentGraph() { return parent ; }
+
+ @Override
+ public ReificationStyle getStyle() { return style ; }
+
+ @Override
+ public boolean handledAdd( Triple t ) { return false ; }
+
+ @Override
+ public boolean handledRemove( Triple t ) { return false ; }
+
+ @Override
+ public boolean hasTriple( Node n )
+ { return getTriple( n ) != null ; }
+
+ @Override
+ public boolean hasTriple( Triple t )
+ {
+ Triple tr = null ;
+ ExtendedIterator<Node> iterNodes = allNodes( t ) ;
+ while( iterNodes.hasNext() ) tr = getTriple( iterNodes.next() ) ;
+ return tr != null ;
+ }
+
+ @Override
+ public Node reifyAs( Node n, Triple t )
+ {
+ Triple tr = getTriple( n ) ;
+ if( tr != null )
+ { if( !t.equals( tr ) ) throw new AlreadyReifiedException( n ) ; }
+ else
+ { parentAddQuad( n, t ) ; if( getTriple( n ) == null ) throw new CannotReifyException( n ) ; }
+ if( concealing == false ) parentAddQuad( n, t ) ;
+ return n ;
+ }
+
+ private void parentAddQuad( Node n, Triple t )
+ {
+ parent.add( Triple.create( n, RDF.Nodes.subject, t.getSubject() ) ) ;
+ parent.add( Triple.create( n, RDF.Nodes.predicate, t.getPredicate() ) ) ;
+ parent.add( Triple.create( n, RDF.Nodes.object, t.getObject() ) ) ;
+ parent.add( Triple.create( n, RDF.Nodes.type, RDF.Nodes.Statement ) ) ;
+ }
+
+ @Override
+ public void remove( Triple t )
+ { if( concealing == false ) parent.delete( t ) ; }
+
+ @Override
+ public void remove( Node n, Triple t )
+ { Triple tr = getTriple( n ); if( tr != null && tr.equals( t ) && concealing == false ) parentRemoveQuad( n, t ) ; }
+
+ private void parentRemoveQuad( Node n, Triple t )
+ {
+ parent.delete( Triple.create( n, RDF.Nodes.type, RDF.Nodes.Statement ) );
+ parent.delete( Triple.create( n, RDF.Nodes.subject, t.getSubject() ) );
+ parent.delete( Triple.create( n, RDF.Nodes.predicate, t.getPredicate() ) );
+ parent.delete( Triple.create( n, RDF.Nodes.object, t.getObject() ) );
+ }
+
+ @Override
+ public int size()
+ {
+ ExtendedIterator<Triple> eit = parent.find( Node.ANY, RDF.type.asNode(), RDF.Statement.asNode() );
+ int count = 0;
+ while( eit.hasNext() ) { eit.next(); count++; }
+ return count * 4;
+ }
+
+ private boolean matchesReification( TripleMatch m )
+ {
+ Node predicate = m.asTriple().getPredicate();
+ return
+ !predicate.isConcrete()
+ || predicate.equals( RDF.Nodes.subject )
+ || predicate.equals( RDF.Nodes.predicate )
+ || predicate.equals( RDF.Nodes.object )
+ || ( predicate.equals( RDF.Nodes.type ) && matchesStatement( m.asTriple().getObject() ) ) ;
+ }
+
+ private boolean matchesStatement( Node x )
+ { return !x.isConcrete() || x.equals( RDF.Nodes.Statement ); }
+}
View
39 src/main/java/com/talis/hbase/rdf/graph/TransactionHandlerHBaseRdf.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import com.hp.hpl.jena.graph.TransactionHandler;
+import com.hp.hpl.jena.graph.impl.TransactionHandlerBase;
+
+public class TransactionHandlerHBaseRdf extends TransactionHandlerBase implements TransactionHandler
+{
+ private final GraphHBaseRdf graph ;
+
+ public TransactionHandlerHBaseRdf ( GraphHBaseRdf graph ) { this.graph = graph ; }
+
+ @Override
+ public void abort() { throw new UnsupportedOperationException( "HBase RDF: 'abort' of a transaction not supported" ) ; }
+
+ @Override
+ public void begin() {}
+
+ @Override
+ public void commit() { graph.sync( true ) ; }
+
+ @Override
+ public boolean transactionsSupported() { return false ; }
+}
View
45 src/main/java/com/talis/hbase/rdf/graph/UpdateListener.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.graph;
+
+import org.openjena.atlas.lib.Sync;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.sparql.modify.GraphStoreEvents;
+import com.hp.hpl.jena.sparql.util.graph.GraphListenerBase;
+
+public class UpdateListener extends GraphListenerBase
+{
+ Sync sync ;
+
+ public UpdateListener( Sync g ) { sync = g ; }
+
+ @Override
+ public void notifyEvent( Graph source, Object value )
+ {
+ if ( value.equals( GraphStoreEvents.RequestStartEvent ) ) {}
+ else if ( value.equals( GraphStoreEvents.RequestFinishEvent ) ) { sync.sync( false ) ; }
+ super.notifyEvent( source, value ) ;
+ }
+
+ @Override
+ protected void addEvent( Triple t ) {}
+
+ @Override
+ protected void deleteEvent( Triple t ) {}
+}
View
74 src/main/java/com/talis/hbase/rdf/iterator/AbstractIterator.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.iterator;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import com.hp.hpl.jena.util.iterator.NiceIterator;
+
+/**
+ * An abstract class for the iterators used.
+ */
+public abstract class AbstractIterator<T> extends NiceIterator<T>
+{
+ private T obj = null;
+
+ @Override
+ public void close() {}
+
+ public abstract T _next() ;
+
+ @Override
+ public boolean hasNext()
+ {
+ if( obj == null ) obj = _next() ;
+ return obj != null ;
+ }
+
+ @Override
+ public T next()
+ {
+ if( obj == null ) { obj = _next() ; if( obj == null ) { throw new NoSuchElementException() ; } }
+ T result = obj ; obj = null ; return result ;
+ }
+
+ @Override
+ public void remove() { throw new UnsupportedOperationException() ; }
+
+ @Override
+ public T removeNext() { throw new UnsupportedOperationException() ; }
+
+ @Override
+ public List<T> toList()
+ {
+ List<T> list = new ArrayList<T>() ;
+ while( hasNext() ) { list.add( next() ) ; }
+ return list ;
+ }
+
+ @Override
+ public Set<T> toSet()
+ {
+ Set<T> set = new HashSet<T>() ;
+ while( hasNext() ) { set.add( next() ) ; }
+ return set ;
+ }
+}
View
63 src/main/java/com/talis/hbase/rdf/iterator/IteratorOfIterators.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright © 2010 Talis Systems Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.talis.hbase.rdf.iterator;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IteratorOfIterators<T> implements Iterator<T>
+{
+ private Iterator<T> currentIter = null ;
+ private List<Iterator<T>> arr ;
+ private Iterator<Iterator<T>> arrIter ;
+
+ public IteratorOfIterators() { arr = new ArrayList<Iterator<T>>() ; }
+
+ public void add( Iterator<T> e ) { arr.add( e ) ; }
+
+ public void closeArr() { arrIter = arr.iterator() ; }
+
+ @Override
+ public boolean hasNext()
+ {
+ if( currentIter != null && currentIter.hasNext() ) return true ;
+
+ while( arrIter.hasNext() )
+ {
+ currentIter = arrIter