Class: RdfStore
- Inherits:
-
Object
- Object
- RdfStore
- Defined in:
- app/models/rdf_store.rb
Overview
Copyright 2011 innoQ Deutschland GmbH
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.
Constant Summary collapse
- @@conn =
nil
Class Method Summary collapse
- .delete(graph_uri) ⇒ Object
- .insert(graph_uri, ttl_url) ⇒ Object
- .mass_import(graph_uri, turtle_content) ⇒ Object
- .update(graph_uri, ttl_url) ⇒ Object
Instance Method Summary collapse
-
#initialize(graph_uri, ttl_url, do_delete, ttl_content = nil) ⇒ RdfStore
constructor
A new instance of RdfStore.
- #run ⇒ Object
Constructor Details
#initialize(graph_uri, ttl_url, do_delete, ttl_content = nil) ⇒ RdfStore
Returns a new instance of RdfStore.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/rdf_store.rb', line 33 def initialize(graph_uri, ttl_url, do_delete, ttl_content = nil) if Rails.application.config.virtuoso_jdbc_driver_url @graph_uri = graph_uri @ttl_url = ttl_url @ttl_content = ttl_content @do_delete = do_delete Rails.logger.info("** [RdfStore] Beginning virtuoso sync. Insert turtle into graph <#{@graph_uri}> from url: #{@ttl_url}; Clear graph first: #{@do_delete}.") unless @@conn # import "virtuoso.jdbc3.Driver" java.lang.Class.forName("virtuoso.jdbc3.Driver", true, JRuby.runtime.jruby_class_loader) @@conn = java.sql.DriverManager.getConnection(Rails.application.config.virtuoso_jdbc_driver_url) Rails.logger.debug("** [RdfStore] JDBC connection is up.") end if Rails.application.config.virtuoso_sync_threaded Rails.logger.debug("** [RdfStore] Starting sync thread.") java.lang.Thread.new(self).start else self.run end end end |
Class Method Details
.delete(graph_uri) ⇒ Object
70 71 72 73 74 |
# File 'app/models/rdf_store.rb', line 70 def self.delete(graph_uri) return false unless Rails.application.config.virtuoso_jdbc_driver_url RdfStore.new(graph_uri, nil, true) true end |
.insert(graph_uri, ttl_url) ⇒ Object
58 59 60 61 62 |
# File 'app/models/rdf_store.rb', line 58 def self.insert(graph_uri, ttl_url) return false unless Rails.application.config.virtuoso_jdbc_driver_url RdfStore.new(graph_uri, ttl_url, false) true end |
Instance Method Details
#run ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/rdf_store.rb', line 82 def run if (@do_delete) Rails.logger.debug("** [RdfStore] Executing SPARQL DELETE.") @@conn.createStatement().execute("SPARQL CLEAR GRAPH <#{@graph_uri}>") end if (@ttl_url) Rails.logger.debug("** [RdfStore] Executing turtle load from url.") @@conn.createStatement().execute("DB.DBA.TTLP(HTTP_GET('#{@ttl_url}'), '', '#{@graph_uri}')") end if (@ttl_content) @@conn.createStatement().execute("DB.DBA.TTLP('#{@ttl_content.gsub("\\", "\\\\\\").gsub("'", "\\\\'")}', '', '#{@graph_uri}')") end Rails.logger.info("** [RdfStore] Virtuoso sync done.") end |