Class: ExistDB::Embedded

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/existdb/embedded.rb

Defined Under Namespace

Classes: InstanceNotRunning

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEmbedded

Returns a new instance of Embedded.



7
8
9
10
11
12
13
14
15
16
# File 'lib/existdb/embedded.rb', line 7

def initialize
  @username ||= 'admin'
  @password ||= ''
  @properties ||= {'create-database' => 'true'}
  @url ||= "exist:///db"

  at_exit do
    stop if running?
  end
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/existdb/embedded.rb', line 5

def password
  @password
end

#propertiesObject

Returns the value of attribute properties.



5
6
7
# File 'lib/existdb/embedded.rb', line 5

def properties
  @properties
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/existdb/embedded.rb', line 5

def url
  @url
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/existdb/embedded.rb', line 5

def username
  @username
end

Instance Method Details

#broker_poolObject

org.exist.storage.BrokerPool

Raises:



62
63
64
65
# File 'lib/existdb/embedded.rb', line 62

def broker_pool
  raise InstanceNotRunning if stopped?
  org.exist.storage.BrokerPool.getInstance(@impl.getName)
end

#dbObject

Raises:



47
48
49
50
# File 'lib/existdb/embedded.rb', line 47

def db
  raise InstanceNotRunning if stopped?
  ClassWrap[ @base_collection ]
end

#inspectObject



52
53
54
# File 'lib/existdb/embedded.rb', line 52

def inspect
  "#<#{self.class}:#{self.hash.to_s(16)} #{running? ? 'running' : 'stopped'}>"
end

#running?Boolean Also known as: started?

Returns:

  • (Boolean)


30
31
32
# File 'lib/existdb/embedded.rb', line 30

def running?
  @running
end

#startObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/existdb/embedded.rb', line 18

def start
  return false if running?
  @impl = org.exist.xmldb.DatabaseImpl.new
  @properties.each{ |key, value| @impl.setProperty(key.to_s, value.to_s) }
  org.xmldb.api.DatabaseManager.registerDatabase(@impl)
  @base_collection = @impl.getCollection(@url, @username, @password)
  @database_instance_manager = @base_collection.getService('DatabaseInstanceManager', '1.0')
  @collection_manager = @base_collection.getService('CollectionManager', '1.0')

  @running = true
end

#stopObject



36
37
38
39
40
41
# File 'lib/existdb/embedded.rb', line 36

def stop
  return false if stopped?
  @database_instance_manager.shutdown
  @running = false
  true
end

#stopped?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/existdb/embedded.rb', line 43

def stopped?
    not running?
end

#transactionObject

org.exist.storage.txn.Txn

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/existdb/embedded.rb', line 68

def transaction # :yields: transaction
  raise InstanceNotRunning if stopped?
  mgr = broker_pool.getTransactionManager
  txn = mgr.beginTransaction
  begin
    yield txn
    mgr.commit(txn)
  rescue
    mgr.abort(txn)
    raise
  end
end

#xquery_serviceObject

Raises:



56
57
58
59
# File 'lib/existdb/embedded.rb', line 56

def xquery_service
  raise InstanceNotRunning if stopped?
  ClassWrap[ @base_collection.getService('XQueryService', '1.0') ]
end