Class: RDF::AllegroGraph::Repository

Inherits:
AbstractRepository show all
Defined in:
lib/rdf/allegro_graph/repository.rb

Overview

An AllegroGraph RDF repository.

Note that this class does not interoperate well with the Unix fork command if you're using blank nodes. See README.md for details.

Instance Method Summary collapse

Methods inherited from AbstractRepository

#build_query, #clear, #each, #has_statement?, #prolog_query, #serialize, #serialize_prolog, #sparql_query, #supports?

Constructor Details

#initialize(options) ⇒ Repository #initialize(url, options) ⇒ Repository

Create a new AllegroGraph repository adapter.

Overloads:

  • #initialize(options) ⇒ Repository

    Parameters:

    • options (Hash{Symbol => Object})

    Options Hash (options):

    • :server (Server)

      The server hosting the repository.

    • :id (String)

      The name of the repository.

    • :create (Boolean)

      Create the repository if necessary?

  • #initialize(url, options) ⇒ Repository

    Parameters:

    • url (String)

      The URL of the repository.

    • options (Hash{Symbol => Object})

    Options Hash (options):

    • :create (Boolean)

      Create the repository if necessary?



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rdf/allegro_graph/repository.rb', line 21

def initialize(url_or_options, options={})
  case url_or_options
  when String
    # TODO: Clean this up.
    url = URI.parse(url_or_options)
    path = Pathname.new(url.path)
    url.path = path.parent.parent.to_s
    server = Server.new(url.to_s).server
    id = path.basename
  else
    server = url_or_options[:server].server
    id = url_or_options[:id]
    options = url_or_options
  end
  super(::AllegroGraph::Repository.new(server, id))
  @repo.create_if_missing! if options[:create]
end

Instance Method Details

#delete!

This method returns an undefined value.

Delete this repository if it exists.



42
43
44
# File 'lib/rdf/allegro_graph/repository.rb', line 42

def delete!
  @repo.delete!
end

#sessionSession #session {|session| ... } ⇒ Object

Create a new, persistent AllegroGraph session. If called without a block, simply returns the new session (and expects the caller to close it). If called with a block, automatically commits or rolls back the transaction, and closes the session.

Overloads:

  • #sessionSession

    Returns The newly created session. It's a good idea to close this manually; doing so frees up server resources.

    Returns:

    • (Session)

      The newly created session. It's a good idea to close this manually; doing so frees up server resources.

    See Also:

  • #session {|session| ... } ⇒ Object

    Returns The result returned from the block.

    Yields:

    • session

    Yield Parameters:

    Yield Returns:

    • (Object)

    Returns:

    • (Object)

      The result returned from the block.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rdf/allegro_graph/repository.rb', line 63

def session
  if block_given?
    session = Session.new(@repo)
    begin
      result = yield session
      session.commit
      result
    rescue => e
      session.rollback
      raise
    ensure
      session.close
    end
  else
    Session.new(@repo)
  end
end