Pierce Ng wrote:
On Wed, Aug 02, 2017 at 11:30:27AM +0200, Herby Vojčík wrote:
Hm, I though that once I open a session it does actually connect on
demand (it has Login, system and all the information for it). Does
it actually mean that if I want to stay connected I must do `session
login` before each `session inUnitOfWorkDo:`?

No.

Great.

As written above, I thought glorp manages this kind of reconnection
itself. If not, can someone point me to the some example where this
is managed? I am asking because in Glorp book I did not find
anything about this (I have read it).

If used with Seaside, typically when a Seaside session is started, your
application's custom subclass of WASession starts a database session, be it for
Glorp, some other OODB, good olde SQL, etc. From Sven's Reddit.st:

   RedditSession>>glorpSession
     glorpSession ifNil: [ glorpSession := self newGlorpSession ].

Yeah, I ended up with this. And planning to set it to nil on each image loading (not sure how, yet, I don't want to register a class as a handler, but I'll manage, I hope).

     glorpSession accessor isLoggedIn
       ifFalse: [ glorpSession accessor login ].

Looking at state of the art code:


DatabaseAccessor >> login
        
        | |
        self loginIfError: [:ex |
                ex pass].
"Just to help avoid confusion if someone thinks they're getting a login object back from this"
        ^nil.


GlorpSession >> isLoggedIn
        ^accessor isLoggedIn


GlorpSession >> login
        self isLoggedIn ifTrue: [^nil].
        ^self loginIfError: [:ex | ex pass]


GlorpSession >> loginIfError: aBlock
        | result |
        result := self accessor loginIfError: aBlock.
        system platform characterEncoding: accessor encoding.
        ^result


it seems this `... ifFalse: ...` is in fact the same thing as `glorpSession login` (yes, it does set an encoding, but otherwise, it's the same, isn't it)?

Doesn't this counter the previous "no", in fact? If I do all operations via `self glorpSession doSomething`, then it actually does `glorpSession login` before each action...

     ^ glorpSession

See the senders of #glorpSession.

Also read the chapters of HPI's Seaside tutorial on tasks&  sessions, and
persistence.

   http://www.hpi.uni-potsdam.de/hirschfeld/seaside/tutorial

1. Link does not load.
2. I am doing it with ZnServer, no Seaside there.

Pierce

Thanks, Herby


Reply via email to