Class: DatalayerLight::MonetDBDrv

Inherits:
Object
  • Object
show all
Defined in:
lib/thm/datalayerlight.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonetDBDrv

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

Parameters:

  • value

    the value to set the attribute autocommit to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def autocommit=(value)
  @autocommit = value
end

#autocommitvalue=(value) ⇒ Object (writeonly)

Sets the attribute autocommitvalue

Parameters:

  • value

    the value to set the attribute autocommitvalue to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def autocommitvalue=(value)
  @autocommitvalue = value
end

#dbnameObject

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

Parameters:

  • value

    the value to set the attribute debug to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def debug=(value)
  @debug = value
end

#hostname=(value) ⇒ Object (writeonly)

Sets the attribute hostname

Parameters:

  • value

    the value to set the attribute hostname to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def hostname=(value)
  @hostname = value
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def password=(value)
  @password = value
end

#port=(value) ⇒ Object (writeonly)

Sets the attribute port

Parameters:

  • value

    the value to set the attribute port to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def port=(value)
  @port = value
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



18
19
20
# File 'lib/thm/datalayerlight.rb', line 18

def username=(value)
  @username = value
end

Instance Method Details

#auto_commit?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/thm/datalayerlight.rb', line 68

def auto_commit?
  @db.auto_commit?
end

#closeObject



115
116
117
# File 'lib/thm/datalayerlight.rb', line 115

def close
  @db.close
end

#commitObject



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

#connectObject



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

#freeObject



111
112
113
# File 'lib/thm/datalayerlight.rb', line 111

def free
  @res.free
end

#is_connected?Boolean

Returns:

  • (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

#releaseObject



60
61
62
# File 'lib/thm/datalayerlight.rb', line 60

def release
  @db.release
end

#rollbackObject



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

#saveObject



56
57
58
# File 'lib/thm/datalayerlight.rb', line 56

def save
  @db.save
end