Class: DatalayerLight::MonetDBDrv
- Inherits:
-
Object
- Object
- DatalayerLight::MonetDBDrv
- Defined in:
- lib/thm/datalayerlight.rb
Instance Attribute Summary collapse
-
#autocommit ⇒ Object
writeonly
Sets the attribute autocommit.
-
#autocommitvalue ⇒ Object
writeonly
Sets the attribute autocommitvalue.
-
#dbname ⇒ Object
Returns the value of attribute dbname.
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#hostname ⇒ Object
writeonly
Sets the attribute hostname.
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#port ⇒ Object
writeonly
Sets the attribute port.
-
#username ⇒ Object
writeonly
Sets the attribute username.
Instance Method Summary collapse
- #auto_commit? ⇒ Boolean
- #close ⇒ Object
- #commit ⇒ Object
- #connect ⇒ Object
- #free ⇒ Object
-
#initialize ⇒ MonetDBDrv
constructor
A new instance of MonetDBDrv.
- #is_connected? ⇒ Boolean
- #query(sql) ⇒ Object
- #release ⇒ Object
- #rollback ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize ⇒ MonetDBDrv
Returns a new instance of MonetDBDrv.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/thm/datalayerlight.rb', line 21 def initialize @hostname = "127.0.0.1" @username = "monetdb" @password = "monetdb" @port = 50000 @dbname = "demo" @debug = 0 @autocommit = false @autocommitvalue = 100 @k = Keycounter.new end |
Instance Attribute Details
#autocommit=(value) ⇒ Object (writeonly)
Sets the attribute autocommit
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def autocommit=(value) @autocommit = value end |
#autocommitvalue=(value) ⇒ Object (writeonly)
Sets the attribute autocommitvalue
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def autocommitvalue=(value) @autocommitvalue = value end |
#dbname ⇒ Object
Returns the value of attribute dbname.
19 20 21 |
# File 'lib/thm/datalayerlight.rb', line 19 def dbname @dbname end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def debug=(value) @debug = value end |
#hostname=(value) ⇒ Object (writeonly)
Sets the attribute hostname
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def hostname=(value) @hostname = value end |
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def password=(value) @password = value end |
#port=(value) ⇒ Object (writeonly)
Sets the attribute port
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def port=(value) @port = value end |
#username=(value) ⇒ Object (writeonly)
Sets the attribute username
18 19 20 |
# File 'lib/thm/datalayerlight.rb', line 18 def username=(value) @username = value end |
Instance Method Details
#auto_commit? ⇒ Boolean
68 69 70 |
# File 'lib/thm/datalayerlight.rb', line 68 def auto_commit? @db.auto_commit? end |
#close ⇒ Object
115 116 117 |
# File 'lib/thm/datalayerlight.rb', line 115 def close @db.close end |
#commit ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/thm/datalayerlight.rb', line 86 def commit begin @db.query("COMMIT;") @k.keycount_reset("COMMITCOUNTER") puts "Syncing data to disk..." rescue MonetDBQueryError puts "Atempting Rollback..." rollback end end |
#connect ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/thm/datalayerlight.rb', line 33 def connect @db = MonetDB.new if @debug == 1 puts "Hostname: #@hostname" puts "Username: #@username" puts "Password: #@password" puts "Port: #@port" puts "Dbname: #@dbname" end begin @db.connect(user = "#@username", passwd = "#@password", lang = "sql", host="#@hostname", port = @port, db_name = "#@dbname", auth_type = "SHA256") rescue Errno::EHOSTUNREACH puts "Please check if the server is running ?" end @db.auto_commit(@autocommit) end |
#free ⇒ Object
111 112 113 |
# File 'lib/thm/datalayerlight.rb', line 111 def free @res.free end |
#is_connected? ⇒ Boolean
64 65 66 |
# File 'lib/thm/datalayerlight.rb', line 64 def is_connected? @db.is_connected? end |
#query(sql) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/thm/datalayerlight.rb', line 97 def query(sql) begin @res = @db.query("#{sql};") print "COMMIT COUNTER: " if @debug == 1 @k.keycount("COMMITCOUNTER") pp @k.keycount_reader("COMMITCOUNTER") if @debug == 1 commit if @k.keycount_reader("COMMITCOUNTER") == @autocommitvalue if @debug == 1; puts "#{sql}"; end rescue MonetDBQueryError rollback end return @res end |
#release ⇒ Object
60 61 62 |
# File 'lib/thm/datalayerlight.rb', line 60 def release @db.release end |
#rollback ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/thm/datalayerlight.rb', line 72 def rollback begin @db.query("ROLLBACK;") puts "Rollback sucess !!!" rescue MonetDBQueryError # Worse case scenario puts "Something went wrong" @db.free @db.close puts "Exiting ..." puts "Bye!" exit end end |
#save ⇒ Object
56 57 58 |
# File 'lib/thm/datalayerlight.rb', line 56 def save @db.save end |