Module: BDBXMLJE
Constant Summary collapse
- DB_ROOT =
db_path
- DB_NAME =
Instance Method Summary collapse
- #create_doc(msg, key) ⇒ Object
- #create_key_and_doc(msg) ⇒ Object
- #find(query) ⇒ Object
- #read_doc(key) ⇒ Object
- #replace_doc(msg, key) ⇒ Object
- #setup_env ⇒ Object
Instance Method Details
#create_doc(msg, key) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/models/modbdbxmlje.rb', line 83 def create_doc(msg,key) #removed the transaction bit since causes error when running inside Tomcat under JRuby #txn = $man.createTransaction() a = $man.createDocument() a.setContent(msg) a.setName(key) $con.putDocument(key,msg) #$con.putDocument(txn,key,msg) #txn.commit() end |
#create_key_and_doc(msg) ⇒ Object
73 74 75 76 77 |
# File 'lib/models/modbdbxmlje.rb', line 73 def create_key_and_doc(msg) key = UUID.new create_doc(msg,key) key end |
#find(query) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/models/modbdbxmlje.rb', line 105 def find(query) cxt = $man.createQueryContext() results = $man.query(query, cxt) if (results.size() == 0) then return nil end #results is essentially an array of result lines #a single result will span a number of output lines, e.g. outer joined #MTA info will appear with a CRLF separator #the following code makes up single logical result rows based on the lines between #successive pairs of {} braces # #it should be noted that the result set from the xqueries is intended to be #a valid ruby block #this allows the result to be used to instantiate an active record object #with no further manipulation required rows = [] i = 0 while results.hasNext() if rows[i] == nil rows[i] = "" end r = results.next().asString() rows[i] << r.chomp if (r.match(']}')) i = i + 1 end end rows end |
#read_doc(key) ⇒ Object
79 80 81 |
# File 'lib/models/modbdbxmlje.rb', line 79 def read_doc(key) $con.getDocument(key).getContentAsString() end |
#replace_doc(msg, key) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/models/modbdbxmlje.rb', line 94 def replace_doc(msg,key) #removed the transaction bit since causes error when running inside Tomcat under JRuby #txn = $man.createTransaction() #a = $con.getDocument(txn,key) a = $con.getDocument(key) a.setContent(msg) #$con.updateDocument(txn,a) $con.updateDocument(a) #txn.commit end |
#setup_env ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/models/modbdbxmlje.rb', line 41 def setup_env #setup UUID state file UUID.config(:state_file => "#{DB_ROOT}/uuid.state", :sequence => rand(0x100000000), :mac_addr => '00:19:e3:36:60:f5') begin envConf = JEnvironmentConfig.new() envConf.setAllowCreate(true) envConf.setTransactional(true) envConf.setInitializeCache(true); f = JFile.new(DB_ROOT) $env = JEnvironment.new(f, envConf); manConf = XmlManagerConfig.new() manConf.setAllowExternalAccess(true) $man = XmlManager.new($env,manConf) if (!File.exist?("#{DB_ROOT}/#{DB_NAME}")) $con = $man.createContainer(DB_NAME) else $con = $man.openContainer(DB_NAME) end $base = "." rescue NativeException => e puts "Native exception's cause: #{e.cause}" raise end end |