Class: ExistDB::Embedded
- Inherits:
-
Object
- Object
- ExistDB::Embedded
- Includes:
- Singleton
- Defined in:
- lib/existdb/embedded.rb
Defined Under Namespace
Classes: InstanceNotRunning
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#broker_pool ⇒ Object
org.exist.storage.BrokerPool.
- #db ⇒ Object
-
#initialize ⇒ Embedded
constructor
A new instance of Embedded.
- #inspect ⇒ Object
- #running? ⇒ Boolean (also: #started?)
- #start ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
-
#transaction ⇒ Object
org.exist.storage.txn.Txn.
- #xquery_service ⇒ Object
Constructor Details
#initialize ⇒ Embedded
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
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/existdb/embedded.rb', line 5 def password @password end |
#properties ⇒ Object
Returns the value of attribute properties.
5 6 7 |
# File 'lib/existdb/embedded.rb', line 5 def properties @properties end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/existdb/embedded.rb', line 5 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/existdb/embedded.rb', line 5 def username @username end |
Instance Method Details
#broker_pool ⇒ Object
org.exist.storage.BrokerPool
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 |
#db ⇒ Object
47 48 49 50 |
# File 'lib/existdb/embedded.rb', line 47 def db raise InstanceNotRunning if stopped? ClassWrap[ @base_collection ] end |
#inspect ⇒ Object
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?
30 31 32 |
# File 'lib/existdb/embedded.rb', line 30 def running? @running end |
#start ⇒ Object
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 |
#stop ⇒ Object
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
43 44 45 |
# File 'lib/existdb/embedded.rb', line 43 def stopped? not running? end |
#transaction ⇒ Object
org.exist.storage.txn.Txn
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_service ⇒ Object
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 |