2 # This is a common base class for database-specific session store implementations
8 # if you need Rails components, and you have a pages which create
9 # new sessions, and embed components insides this pages that need
10 # session access, then you *must* set +eager_session_creation+ to
11 # true (as of Rails 1.0).
12 cattr_accessor :eager_session_creation
13 @@eager_session_creation = false
15 # Some attributes you may want to store natively in the database
16 # in actual columns. This allows other models and database queries
17 # to get to the data without having to unmarshal the data blob.
18 # One common example is the user_id of the session, so it can be
19 # related to the users table
20 cattr_accessor :native_columns
23 # Allow the user to change the table name
24 cattr_accessor :table_name
25 @@table_name = 'sessions'
27 cattr_reader :timestamp_columns
28 @@timestamp_columns = [:created_at, :updated_at]
30 attr_accessor :id, :session_id, :data
32 def initialize(session_id, data, id=nil)
33 @session_id = session_id
39 # delete all sessions meeting a given +condition+. it is the
40 # caller's responsibility to pass a valid sql condition
41 def delete_all(condition=nil)
43 session_connection.exec("DELETE FROM sessions WHERE #{condition}")
45 session_connection.exec("DELETE FROM sessions")
49 # retrieve the session table connection and get the 'raw' driver connection from it
50 def session_connection
51 SqlSession.connection.raw_connection
54 def unmarshalize(data)
55 Marshal.load(Base64.decode64(data))
59 Base64.encode64(Marshal.dump(data))
66 # This software is released under the MIT license
68 # Copyright (c) 2005, 2006, 2008 Stefan Kaes
69 # Copyright (c) 2008, 2009 Nate Wiger
71 # Permission is hereby granted, free of charge, to any person obtaining
72 # a copy of this software and associated documentation files (the
73 # "Software"), to deal in the Software without restriction, including
74 # without limitation the rights to use, copy, modify, merge, publish,
75 # distribute, sublicense, and/or sell copies of the Software, and to
76 # permit persons to whom the Software is furnished to do so, subject to
77 # the following conditions:
79 # The above copyright notice and this permission notice shall be
80 # included in all copies or substantial portions of the Software.
82 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
83 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
85 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
86 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
87 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
88 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.