rb_cObject
An RDF triplestore abstract base class
$Id$
Copyright © 2008-2009, Michael Granger All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Class attribute: a Hash of loaded concrete Redleaf::Store classes keyed by name. E.g,. the Redleaf::HashesStore would be associated with the ‘hashes’ key. See the Redleaf::Store.backends hash for storage types supported in the current environment.
Set the class’s Redland backend to new_setting if given, and return the current (new) setting.
# File lib/redleaf/store.rb, line 57 57: def self::backend( new_setting=nil ) 58: if new_setting 59: Redleaf.logger.debug "Setting backend for %p to %p" % [ self, new_setting ] 60: @backend = new_setting 61: Redleaf::Store.register( self, @backend ) 62: 63: unless self.is_supported? 64: Redleaf.logger.warn "local Redland library doesn't have the %p store; valid values are: %p" % 65: [ @backend.to_s, self.backends.keys ] 66: end 67: end 68: 69: return @backend 70: end
Return a Hash of supported backends from the underlying Redland library.
Redleaf::Store.backends # => {"uri"=>"URI store (read-only)", # "memory"=>"In memory", # "trees"=>"Balanced trees", # "sqlite"=>"SQLite", # "postgresql"=>"postgresql database store", # "file"=>"Local file based store", # "hashes"=>"Indexed hashes"}
static VALUE rleaf_redleaf_store_s_backends( VALUE klass )
Attempt to load the Redleaf::Store concrete class that wraps the given backend, create one with the specified args, and return it.
# File lib/redleaf/store.rb, line 130 130: def self::create( backend, *args ) 131: require "redleaf/store/#{backend}" 132: subclass = self.derivatives[ backend.to_sym ] or 133: raise "Ack! Loading the %p backend didn't register a subclass." % [ backend ] 134: 135: return subclass.new( *args ) 136: end
Returns true if the Redland backend required by the receiving store class is supported by the local installation.
# File lib/redleaf/store.rb, line 86 86: def self::is_supported?( storetype=nil ) 87: if storetype 88: return self.backends.include?( storetype.to_s ) 89: else 90: return self.backends.include?( self.backend.to_s ) 91: end 92: end
Attempt to load the Redleaf::Store concrete class that wraps the given backend, load one (via its ::load method) with the specified args, and return it.
# File lib/redleaf/store.rb, line 141 141: def self::load( backend, *args ) 142: require "redleaf/store/#{backend}" 143: subclass = self.derivatives[ backend.to_sym ] or 144: raise "Ack! Loading the %p backend didn't register a subclass." % [ backend ] 145: 146: return subclass.load( *args ) 147: end
Make a Redland-style opthash pair String out of the specified key/value pair.
# File lib/redleaf/store.rb, line 99 99: def self::make_optpair( *pair ) 100: key, value = *(pair.flatten) 101: name = key.to_s.gsub( /_/, '-' ) 102: value = case value 103: when FalseClass 104: 'no' 105: when TrueClass 106: 'yes' 107: when NilClass 108: '' 109: else 110: value 111: end 112: 113: return "%s='%s'" % [ name, value ] 114: end
Make a librdf_hash-style optstring from the given opthash and return it.
# File lib/redleaf/store.rb, line 118 118: def self::make_optstring( opthash ) 119: Redleaf.logger.debug "Making an optstring from hash: %p" % [ opthash ] 120: filter = self.method( :make_optpair ) 121: optstring = opthash.collect( &filter ).join( ', ' ) 122: Redleaf.logger.debug " optstring is: %p" % [ optstring ] 123: 124: return optstring 125: end
Create a new Redleaf::Store object. .
static VALUE rleaf_redleaf_store_initialize( int argc, VALUE *argv, VALUE self )
Register the given subclass as being implemented by the specified backend.
# File lib/redleaf/store.rb, line 49 49: def self::register( subclass, backend ) 50: Redleaf.logger.debug "Registering %p as the %p backend" % [ subclass, backend ] 51: @derivatives[ backend.to_sym ] = subclass 52: end
Get the backend name for the class after making sure it’s valid and supported by the local installation. Raises a Redleaf::FeatureError if there is a problem.
# File lib/redleaf/store.rb, line 75 75: def self::validated_backend 76: raise Redleaf::FeatureError, "unsupported backend %p" % [ self.backend ] unless 77: self.is_supported? 78: 79: return self.backend 80: end
Return the Redleaf::Graph associated with this Store, creating one if one if necessary.
static VALUE rleaf_redleaf_store_graph( VALUE self )
Set the store’s graph to newgraph, discarding any previous graph.
static VALUE rleaf_redleaf_store_graph_eq( VALUE self, VALUE graphobj )
Return true if the backend of the receiver supports contexts and the receiver has them enabled.
static VALUE rleaf_redleaf_store_has_contexts_p( VALUE self )
Return a human-readable representation of the object suitable for debugging.
# File lib/redleaf/store.rb, line 161 161: def inspect 162: return "#<%s:0x%x name: %s, options: %p, graph: %p>" % [ 163: self.class.name, 164: self.class.object_id * 2, 165: self.name, 166: self.opthash, 167: self.graph, 168: ] 169: end
Returns true if the Store persists after the process has exited.
# File lib/redleaf/store.rb, line 155 155: def persistent? 156: return false 157: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.