[hidden email] wrote:
> Herby, > > I am not aware of any automatic reconnect tools. Kepping a DB connection > alive after an image is closed is surely not desired and chances are the > DB will close the inactive session eventually anyways. Hm. When I though about it, image save / load cycle is just one example of losing a connection to db. So the question is more on "how to manage possible disconnections / reconnections"? > So it's probably best to make the DB connections reconnect on demand. > That means that whenever you open a session, check if a DB connection is > available or establish a new one otherwise. 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:`? > There are many scenarios that can lead to the loss of a DB connection > that you usually cannot influence (network connection drops, DB server > has some error condition etc.) , so this is a good idea anyways. 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). Thanks, Herby > HTH > > Joachim > > > Am 01.08.17 um 22:29 schrieb Herby Vojčík: >> Hello! >> >> ZnServers have its own register mechanism by which they listen when >> they are tagged as such after image save and load. >> >> I wonder if there is some way to connect to database in Glorp and then >> "keep the connection" between image save/load. Or how is this managed >> notmally in apps that use databases? Is image "preconfigured" with >> live self-healing connection or does some special piece of startup >> code be installed so it runs after deployment and image start? >> >> Thanks, Herby >> >> > > |
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. > 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 ]. glorpSession accessor isLoggedIn ifFalse: [ glorpSession accessor login ]. ^ 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 Pierce |
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 |
On Thu, Aug 03, 2017 at 03:27:16PM +0200, Herby Vojčík wrote:
> Looking at state of the art code: > GlorpSession >> loginIfError: aBlock > | result | > result := self accessor loginIfError: aBlock. > system platform characterEncoding: accessor encoding. > ^result In the line "result := self accessor loginIfError: aBlock", "self accessor" is not an instance of DatabaseAccessor, because DatabaseAccessor>>loginIfError: aBlock self subclassResponsibility "self accessor" is an instance of PharoDatabaseAccessor, and PharoDatabaseAccessor>>loginIfError: aBlock self log: 'Login'. self databaseDriver: self connectionClass new. self execute: [ self databaseDriver connect: currentLogin. currentLogin secure ifTrue: [ currentLogin discardPassword ] ] ifError: aBlock. self log: 'Login finished' PharoDatabaseAccessor>>isLoggedIn self databaseDriver ifNil: [^ false]. ^ self databaseDriver isConnected Connecting to my instance of Reddit (actually RedditSt20 using SQLite not PostgreSQL), adding a link and then clicking refresh, Transcript shows: Login Login finished SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.points DESC LIMIT 20 an OrderedCollection() SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.created DESC LIMIT 20 an OrderedCollection() Begin Transaction INSERT INTO REDDIT_LINKS (url,title,created,points) VALUES (?,?,?,?) an Array('http://planet.smalltalk.org' 'Planet Smalltalk' 2017-08-04T22:25:14.558667+08:00 0) SELECT last_insert_rowid() (0.0 s) Commit Transaction SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.points DESC LIMIT 20 an OrderedCollection() SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.created DESC LIMIT 20 an OrderedCollection() Login happened once. Clicking "New Session": Logout Logout finished Login Login finished SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.points DESC LIMIT 20 an OrderedCollection() SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.created DESC LIMIT 20 an OrderedCollection() Clicking "Refresh" in the application: SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.points DESC LIMIT 20 an OrderedCollection() SELECT t1.id, t1.url, t1.title, t1.created, t1.points FROM REDDIT_LINKS t1 ORDER BY t1.created DESC LIMIT 20 an OrderedCollection() Pierce |
Free forum by Nabble | Edit this page |