Re: ERXEOAccessUtilities.closeDatabaseConnections and snapshots

Larry Mills-Gahl <[email protected]>
Newsgroups gmane.comp.web.webobjects.wonder-disc
Message-ID <[email protected]>
I have one model that changes database connection based on action from the user (who is logged in, what database their data is in). The other models always connect to the same database for the app. 

One utility I have for reporting iterates through clients, disposes the existing ec, creates a new one, connects with the new connection dictionary, sets the fetch timestamp etc and processes data from that database. I was finding that when two consecutive clients happen to have objects with the same GID as part of the report, the person record would be pulled from the snapshot even as the related data was fetched from the database. The result is that the person name was wrong, but the report data was correct. 

DB1
	personA pk 1
	personB pk 10
	personC pk 16
	personD pk 20

DB2
	person1 pk 1
	person2 pk 2
	person3 pk 15
	person4 pk 20


In the preceding data set, if I run the client in DB1, then the client in DB2, the report for the client in DB2 would show:

personA pk 1
person2 pk 2
person3 pk 15
personD pk 20

All of the related data would be refetched (I'm guessing because the GID's were different) so the report was correct… except for the name… which is a bit of a problem.

The solution that is working in local tests is to forget the snapshots for the relevant database context:
ERXEOAccessUtilities.closeDatabaseConnections(osc);
EOEditingContext ec = ERXEC.newEditingContext(osc);
EOUtilities.connectWithModelNamed(ec, VASession.EMR_MODEL_NAME, cdict);
EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(EOModelGroup.defaultGroup().modelNamed(EMR_MODEL_NAME), ec);
dbc.database().forgetAllSnapshots();


It seems counter-intuitive for the snapshot to remain after the database connections are closed, but there is always something new to learn about EOF and it's usually more well thought out than my first impressions. 



On Mar 12, 2013, at 12:14 PM, Chuck Hill <[email protected]> wrote:

> Doesn't that also mean that there are ECs and EOs live that are using that snapshot?  Discarding it might be a problem for them.
> 
> What problem did you run into?
> 
> Chuck
> 
> On 2013-03-12, at 7:14 AM, Larry Mills-Gahl wrote:
> 
>> Does anybody see a problem with forgetting snapshots as part of the ERXEOAccessUtilities.closeDatabaseConnections?
>> I ran into a problem when switching a model to a different database where after ERXEOAccessUtilities.closeDatabaseConnections there were still snapshots around with data from the old database. 
>> I cannot think of a reason why data from a disconnected database should remain in a snapshot (but just because I cannot think of a reason doesn't mean there isn't one.)
>> 
>> 
>> 
>> Larry Mills-Gahl
>> [email protected]
>> 
>> 
>> 
>> 
>> 
>> 
>> ------------------------------------------------------------------------------
>> Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
>> Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
>> endpoint security space. For insight on selecting the right partner to 
>> tackle endpoint security challenges, access the full report. 
>> http://p.sf.net/sfu/symantec-dev2dev_______________________________________________
>> Wonder-disc mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/wonder-disc
> 
> -- 
> Chuck Hill             
> Executive Managing Partner, VP Development and Technical Services
> 
> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.    
> http://www.global-village.net/gvc/practical_webobjects
> 
> Global Village Consulting ranks 13th in 2012 in BIV's Top 100 Fastest Growing Companies in B.C! 
> Global Village Consulting ranks 76th in 24th annual PROFIT 200 ranking of Canada’s Fastest-Growing Companies by PROFIT Magazine!
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar

_______________________________________________
Wonder-disc mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wonder-disc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.