-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to latest version of everything, including the working big_tab…
…le_servlet_store.
- Loading branch information
Showing
5 changed files
with
58 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
# $servlet_context.log("LOOOOOOOOOOOOOOOOOOOOOOOOOOOADING BigTableServletStore") | ||
|
||
# include_class "com.google.appengine.api.datastore.DatastoreServiceFactory" | ||
|
||
# class CGI #:nodoc:all | ||
# class Session | ||
# class BigTableServletStore | ||
# DATASTORE = DatastoreServiceFactory.datastore_service | ||
module Google | ||
import com.google.appengine.api.datastore.DatastoreServiceFactory | ||
import com.google.appengine.api.datastore.Entity | ||
import com.google.appengine.api.datastore.KeyFactory | ||
import com.google.appengine.api.datastore.Key | ||
import com.google.appengine.api.datastore.EntityNotFoundException | ||
end | ||
|
||
class CGI #:nodoc:all | ||
class Session | ||
class BigTableServletStore | ||
DATASTORE = Google::DatastoreServiceFactory.datastore_service | ||
RAILS_SESSION_ENTITY = "__current_rails_session" | ||
RAILS_SESSION_KEY = "__rails_session_data" | ||
|
||
# def initialize(session, option=nil) | ||
# $servlet_context.log("BigTableServletStore.initialize") | ||
# end | ||
|
||
# def restore | ||
# $servlet_context.log("BigTableServletStore.restore") | ||
# end | ||
|
||
# def update | ||
# $servlet_context.log("BigTableServletStore.update") | ||
# end | ||
|
||
# def close | ||
# $servlet_context.log("BigTableServletStore.close") | ||
# end | ||
|
||
# def delete | ||
# $servlet_context.log("BigTableServletStore.delete") | ||
# end | ||
|
||
# def data | ||
# $servlet_context.log("BigTableServletStore.data") | ||
# end | ||
|
||
# def []=(k, v) | ||
# $servlet_context.log("BigTableServletStore.[]=") | ||
# end | ||
|
||
# def [](k) | ||
# $servlet_context.log("BigTableServletStore.[]") | ||
# end | ||
|
||
# def each(&b) | ||
# $servlet_context.log("BigTableServletStore.each") | ||
# end | ||
|
||
# private | ||
# # Attempts to redirect any messages to the data object. | ||
# def method_missing(name, *args, &block) | ||
# end | ||
# end | ||
# end | ||
# end | ||
def initialize(session, option=nil) | ||
@session_id = session.session_id | ||
@key = Google::KeyFactory.create_key(RAILS_SESSION_ENTITY, @session_id) | ||
@data = {} | ||
end | ||
def marshal(data) ActiveSupport::Base64.encode64(Marshal.dump(data)) if data end | ||
def unmarshal(data) Marshal.load(ActiveSupport::Base64.decode64(data)) if data end | ||
|
||
# Restore session state from the big table session | ||
def restore | ||
begin | ||
entity = DATASTORE.get(@key) | ||
if entity.has_property(RAILS_SESSION_KEY) | ||
@data = unmarshal(entity.get_property(RAILS_SESSION_KEY)) | ||
end | ||
rescue Google::EntityNotFoundException | ||
end | ||
|
||
@data | ||
end | ||
|
||
def update | ||
entity = Google::Entity.new(RAILS_SESSION_ENTITY, @session_id) | ||
entity.set_property(RAILS_SESSION_KEY, marshal(@data)) | ||
DATASTORE.put(entity) | ||
end | ||
|
||
def close | ||
update | ||
end | ||
|
||
def delete | ||
DATASTORE.delete(@key) | ||
end | ||
end | ||
end | ||
end |