class BtrieveSession SESSIONS = {} include Btrieve attr_reader :pathname, :client_id, :cache, :model_classes, :btrieve_schema attr_accessor :btrieve_map def self.set_context(pathname) session = get_session if session raise Exception.new("The existing context in the current is set to a different pathname.") if(session.pathname != pathname) else SESSIONS[Thread.current] = new(pathname) end end def self.get_session SESSIONS[Thread.current] end def transaction(&block) btr_op(self, BEGIN_TRANSACTION, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) begin yield rescue Exception => exception btr_op(self, ABORT_TRANSACTION, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) raise Exception.new("PSQL TX ABORTED!!! - #{exception.message}\n#{exception.backtrace.join("\n\t")}") end btr_op(self, END_TRANSACTION, NULL_BUFFER, NULL_BUFFER, NULL_BUFFER, NULL_KEY) end def get_table(url_tablename) tablename=BtrieveTable.url_to_tablename(url_tablename) table=@table_cache[tablename]||=BtrieveTable.new(tablename.to_sym, self) [table,table.version] end private def initialize(pathname) @cache = {} @model_classes = {} @table_cache = {} @pathname = pathname @client_id = "#{0.chr*12}#{[0x5257].pack('S')}#{rand(65535)}" btr_op(self, SET_DIRECTORY, NULL_BUFFER, NULL_BUFFER, @pathname, NULL_KEY) @btrieve_schema = BtrieveSchema.new(self) @btrieve_map = BtrieveMap.new() end end