Changeset 321

Show
Ignore:
Timestamp:
03/02/09 12:16:30 (10 years ago)
Author:
samuraraujo
Message:
 
Location:
Explorator/trunk/vendor/plugins
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • Explorator/trunk/vendor/plugins/active_rdf/lib/active_rdf/federation/connection_pool.rb

    r272 r321  
    66 
    77class ConnectionPool 
    8         class << self 
    9                 attr_accessor :write_adapter 
    10                 # sets automatic flushing of data from adapters to original datasources  
    11                 # (e.g. redland on-file database). If disabled, changes to an adapter are  
    12                 # not written back into the original source: you need to invoke  
    13                 # ConnectionPool.flush manually 
    14                 bool_accessor :auto_flush 
    15         end 
     8  class << self 
     9    attr_accessor :write_adapter 
     10    # sets automatic flushing of data from adapters to original datasources  
     11    # (e.g. redland on-file database). If disabled, changes to an adapter are  
     12    # not written back into the original source: you need to invoke  
     13    # ConnectionPool.flush manually 
     14    bool_accessor :auto_flush 
     15  end 
    1616  # pool of all adapters 
    1717  @@adapter_pool = Array.new 
    18  
     18   
    1919  # pool of connection parameters to all adapter 
    2020  @@adapter_parameters = Array.new 
    21  
     21   
    2222  # currently active write-adapter (we can only write to one at a time) 
    2323  self.write_adapter = nil 
    24  
    25         # default setting for auto_flush 
    26         self.auto_flush = true 
    27  
     24   
     25  # default setting for auto_flush 
     26  self.auto_flush = true 
     27   
    2828  # adapters-classes known to the pool, registered by the adapter-class 
    2929  # itself using register_adapter method, used to select new 
    3030  # adapter-instance for requested connection type 
    3131  @@registered_adapter_types = Hash.new 
    32  
     32   
    3333  # clears the pool: removes all registered data sources 
    3434  def ConnectionPool.clear 
     
    3838    self.write_adapter = nil 
    3939  end 
    40  
     40   
    4141  def ConnectionPool.adapters 
    4242    @@adapter_pool.dup 
    4343  end 
    44  
    45         # flushes all openstanding changes into the original datasource. 
    46         def ConnectionPool.flush 
    47                 write_adapter.flush 
    48         end 
    49  
    50         def ConnectionPool.adapter_types 
    51                 @@registered_adapter_types.keys 
    52         end 
    53  
     44   
     45  # flushes all openstanding changes into the original datasource. 
     46  def ConnectionPool.flush 
     47    write_adapter.flush 
     48  end 
     49   
     50  def ConnectionPool.adapter_types 
     51    @@registered_adapter_types.keys 
     52  end 
     53   
    5454  # returns the set of currently registered read-access datasources 
    5555  def ConnectionPool.read_adapters 
    5656    @@adapter_pool.select {|adapter|  
    57     (adapter.reads? &&  adapter.enabled?) 
     57     (adapter.reads? &&  adapter.enabled?) 
    5858    } 
    5959  end 
     
    6161     
    6262    @@adapter_pool.select {|x| (x.writes? && x.enabled?) } 
    63  
     63     
    6464  end 
    65  
     65   
    6666  # returns adapter-instance for given parameters (either existing or new) 
    6767  def ConnectionPool.add_data_source(connection_params) 
    6868    $activerdflog.info "ConnectionPool: add_data_source with params: #{connection_params.inspect}" 
    69  
     69     
    7070    # either get the adapter-instance from the pool 
    7171    # or create new one (and add it to the pool) 
     
    8585      adapter = @@adapter_pool[index] 
    8686    end 
    87  
     87     
    8888    # sets the adapter as current write-source if it can write 
    8989    self.write_adapter = adapter if adapter.writes? 
    90  
     90     
    9191    return adapter 
    9292  end 
     
    9494  # remove one adapter from activerdf 
    9595  def ConnectionPool.remove_data_source(adapter) 
     96    RDFS::Resource.reset_cache()  
     97      
    9698    $activerdflog.info "ConnectionPool: remove_data_source with params: #{adapter.to_s}" 
    9799     
    98100    index = @@adapter_pool.index(adapter) 
    99  
     101     
    100102    # remove_data_source mit be called repeatedly, e.g because the adapter object is stale 
    101103    unless index.nil? 
    102104      @@adapter_parameters.delete_at(index) 
    103105      @@adapter_pool.delete_at(index) 
    104       if self.write_adapters.empty? 
    105         self.write_adapter = nil 
    106       else 
    107         self.write_adapter = self.write_adapters.first 
    108       end 
     106#      if self.write_adapters.empty? 
     107#        self.write_adapter = nil 
     108#      else 
     109#        self.write_adapter = self.write_adapters.first 
     110#      end 
     111       
    109112    end 
    110113     
    111114  end 
    112  
    113         # sets adapter-instance for connection parameters (if you want to re-enable an existing adapter) 
    114         def ConnectionPool.set_data_source(adapter, connection_params = {}) 
    115                 index = @@adapter_parameters.index(connection_params) 
    116                 if index.nil? 
     115   
     116  # sets adapter-instance for connection parameters (if you want to re-enable an existing adapter) 
     117  def ConnectionPool.set_data_source(adapter, connection_params = {}) 
     118    index = @@adapter_parameters.index(connection_params) 
     119    if index.nil? 
    117120      @@adapter_parameters << connection_params 
    118121      @@adapter_pool << adapter 
    119                 else 
    120                         @@adapter_pool[index] = adapter 
    121                 end 
    122                 self.write_adapter = adapter if adapter.writes? 
    123                 adapter 
    124         end 
    125  
    126         # aliasing add_data_source as add 
    127         # (code bit more complicad since they are class methods) 
    128         class << self 
    129                 alias add add_data_source 
    130         end 
    131  
     122    else 
     123      @@adapter_pool[index] = adapter 
     124    end 
     125    self.write_adapter = adapter if adapter.writes? 
     126    adapter 
     127  end 
     128   
     129  # aliasing add_data_source as add 
     130  # (code bit more complicad since they are class methods) 
     131  class << self 
     132    alias add add_data_source 
     133  end 
     134   
    132135  # adapter-types can register themselves with connection pool by 
    133136  # indicating which adapter-type they are 
     
    136139    @@registered_adapter_types[type] = klass 
    137140  end 
    138  
     141   
    139142  # create new adapter from connection parameters 
    140143  def ConnectionPool.create_adapter connection_params 
    141144    # lookup registered adapter klass 
    142   
     145     
    143146    klass = @@registered_adapter_types[connection_params[:type]] 
    144   
     147     
    145148    # raise error if adapter type unknown 
    146149    raise(ActiveRdfError, "unknown adapter type #{connection_params[:type]}") if klass.nil? 
     
    148151    # create new adapter-instance 
    149152    klass.send(:new,connection_params) 
    150  
     153     
    151154  end 
    152155   
  • Explorator/trunk/vendor/plugins/active_rdf/lib/active_rdf/objectmanager/namespace.rb

    r272 r321  
    8181  # returns local-part of URI 
    8282  def self.localname(resource) 
    83     raise ActiveRdfError, "localname called on something that doesn't respond to uri" unless resource.respond_to? :uri 
     83 
     84    raise ActiveRdfError, "localname ("+resource+") called on something that doesn't respond to uri" unless resource.respond_to? :uri 
    8485    # get string representation of resource uri 
    8586    uri = resource.uri 
  • Explorator/trunk/vendor/plugins/activerdf_sparql-1.3.6/lib/activerdf_sparql/sparql.rb

    r308 r321  
    1515    @sparql_cache = {} 
    1616  end 
    17 #  def SparqlAdapter.get_cache 
    18 #    return @sparql_cache 
    19 #  end 
     17  #  def SparqlAdapter.get_cache 
     18  #    return @sparql_cache 
     19  #  end 
    2020   
    2121  # Instantiate the connection with the SPARQL Endpoint. 
     
    5555  def query(query, &block)     
    5656    qs = Query2SPARQL.translate(query) 
    57    
     57      
    5858    if @caching 
    5959      result = query_cache(qs) 
     
    6565      end 
    6666    end 
    67      
     67    puts qs.to_s 
    6868    result = execute_sparql_query(qs, header(query), &block) 
    6969    add_to_cache(qs, result) if @caching 
    7070    result = [] if result == "timeout" 
    71    #   puts qs.to_s   
     71 
    7272    return result 
    7373  end 
     
    8080    require 'timeout' 
    8181    response = '' 
     82    url ='' 
    8283    begin  
    8384      case @request_method 
    8485        when :get 
    8586        # encoding query string in URL 
    86         url = "#@url?query=#{CGI.escape(qs)}" 
    87          
     87        url = "#@url?query=#{CGI.escape(qs)}"         
    8888        $activerdflog.debug "GET #{url}"         
    8989        timeout(@timeout) do           
    90          # puts url 
    91           open(url, header) do |f| 
    92   
    93             response = f.read             
     90          # puts url 
     91          open(url, header) do |f|             
     92            response = f.read    
     93              puts response 
    9494          end 
    9595        end 
     
    9797        $activerdflog.debug "POST #@url with #{qs}" 
    9898        response = Net::HTTP.post_form(URI.parse(@url),{'query'=>qs}).body        
    99      end 
     99      end 
    100100      #puts response 
    101101    rescue Timeout::Error 
    102       raise ActiveRdfError, "timeout on SPARQL endpoint" 
     102      raise ActiveRdfError, "timeout on SPARQL endpoint. <br><br><b>URI accessed:</b> " + url 
    103103      return "timeout" 
    104104    rescue OpenURI::HTTPError => e 
    105       raise ActiveRdfError, "could not query SPARQL endpoint, server said: #{e}" 
     105      raise ActiveRdfError, "could not query SPARQL endpoint, server said: #{e} . <br><br><b>URI accessed:</b> " + url 
    106106      return [] 
    107107    rescue Errno::ECONNREFUSED 
     
    111111     
    112112    # we parse content depending on the result format 
    113       
     113     
    114114    results = case @result_format 
    115115      when :json  
     
    118118      parse_xml(response) 
    119119    end 
    120   
     120     
    121121    if block_given? 
    122122      results.each do |*clauses| 
     
    132132  private 
    133133  def add_to_cache(query_string, result) 
    134     unless result.nil? or result.empty? 
     134    if result.nil? or result.empty? 
     135      @sparql_cache.store(query_string, []) 
     136    else 
    135137      if result == "timeout" 
    136138        @sparql_cache.store(query_string, []) 
  • Explorator/trunk/vendor/plugins/activerdf_sparql-1.3.6/lib/activerdf_sparql/sparql_sesame_api.rb

    r308 r321  
    6767    add_to_cache(qs, result) if @caching 
    6868    result = [] if result == "timeout" 
     69        puts qs.to_s   
    6970    return result 
    7071  end 
     
    140141  private 
    141142  def add_to_cache(query_string, result) 
    142     unless result.nil? or result.empty? 
     143    if result.nil? or result.empty? 
     144      @sparql_cache.store(query_string, []) 
     145    else 
    143146      if result == "timeout" 
    144147        @sparql_cache.store(query_string, [])