1 require 'active_record'
9 # +SqlSessionStore+ is a stripped down, optimized for speed version of
10 # class +ActiveRecordStore+.
14 # The class to be used for creating, retrieving and updating sessions.
15 # Defaults to SqlSessionStore::Session, which is derived from +ActiveRecord::Base+.
17 # In order to achieve acceptable performance you should implement
18 # your own session class, similar to the one provided for Myqsl.
20 # Only functions +find_session+, +create_session+,
21 # +update_session+ and +destroy+ are required. See file +mysql_session.rb+.
23 cattr_accessor :session_class
24 @@session_class = SqlSession
26 # Create a new SqlSessionStore instance.
28 # +session+ is the session for which this instance is being created.
30 # +option+ is currently ignored as no options are recognized.
32 def initialize(session, option=nil)
33 if @session = @@session_class.find_session(session.session_id)
34 @data = unmarshalize(@session.data)
36 @session = @@session_class.create_session(session.session_id, marshalize({}))
41 # Update the database and disassociate the session object
44 @session.update_session(marshalize(@data))
49 # Delete the current session, disassociate and destroy session object
57 # Restore session data from the session object
60 @data = unmarshalize(@session.data)
64 # Save session data in the session object
67 @session.update_session(marshalize(@data))
73 def unmarshalize(data)
74 Marshal.load(Base64.decode64(data))
78 Base64.encode64(Marshal.dump(data))
81 def unmarshalize(data)
82 Marshal.load(data.unpack("m").first)
86 [Marshal.dump(data)].pack("m")
94 # This software is released under the MIT license
96 # Copyright (c) 2005-2008 Stefan Kaes
98 # Permission is hereby granted, free of charge, to any person obtaining
99 # a copy of this software and associated documentation files (the
100 # "Software"), to deal in the Software without restriction, including
101 # without limitation the rights to use, copy, modify, merge, publish,
102 # distribute, sublicense, and/or sell copies of the Software, and to
103 # permit persons to whom the Software is furnished to do so, subject to
104 # the following conditions:
106 # The above copyright notice and this permission notice shall be
107 # included in all copies or substantial portions of the Software.
109 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
110 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
111 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
112 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
113 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
114 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
115 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.