Hi Kieren

Yeah, I don't use defaultEditingContext, I just was nervous about creating 
editing contexts at the application level. As for experience, I've been doing 
WO development since 2001but I've just never needed database access from the 
application level before. Thanx for the info.

-j

On Nov 25, 2009, at 12:05 PM, Kieran Kelleher wrote:

> Every time your TradeController get s a Trade notification, just do sth like 
> this:
> 
> EOEditingContext ec = new EOEditingContext();
> ec.lock() {
>       
>       // Create new Trade EOs in the ec.
> 
>       // Populate the eo attributes
> 
>       ec.saveChanges();
> } catch (Exception e) {
>       // TODO handle exception
> } finally {
>       ec.unlock();
> }
> 
> 
> Once you get more experience with WebObjects, you will find that 
> session().defaultEditingContext() will be something you will never depend on 
> or use for editing objects ever again .... but that is a discussion for 
> another day ;-)
> 
> 
> HTH, Kieran
> 
> On Nov 25, 2009, at 12:52 PM, Jerald Dawson wrote:
> 
>> Hi All
>> 
>> I have a question about best practices for database access from a wo app. I 
>> will attempt to explain my situation and hopefully someone will give me some 
>> pointers (fingers crossed).
>> 
>> I have an application that listens to our trading server for trade 
>> notifications. It then writes those trades into a database. The way I'm 
>> handling it right now is my TradeController class keeps an array list of all 
>> the trades. My Application instance has the singleton instance of 
>> TradeController. I have it belong to the Application instance because it 
>> defines a connection to the trade server and I only want one of those, not 
>> one for every session. I also need to be getting trade notifications even 
>> when no sessions are present. When someone wants to put the trades into the 
>> database, they connect to the application and go to the Trades page. This 
>> page has a list of all non-processed trades from the TradeController object. 
>> The user then initiates a process which results in all trades from 
>> TradeController being written into the database.
>> 
>> What I would like to do is for the TradeController to have its own path into 
>> the database. That way, as trades come in, the TradeController could just 
>> write them directly into the database without user intervention. The problem 
>> is that the database connections are handled by session() by default. I 
>> would like to just have the TradeController instance create its own 
>> editingContext to the database and use it to write the trades into the 
>> database. The users could then log in and just query the database for 
>> position and P&L info without manually importing the trades.
>> 
>> I'm a bit nervous about having something outside of a session do database 
>> access, mainly because I've never done it before. I wanted to find out if 
>> its ok to do it before I went down that path. I don't want to spend time 
>> writing it only to find out there are show stopping bugs (or design 
>> decisions).
>> 
>> Hopefully I've made myself clear. Any wisdom from the list is appreciated.
>> 
>> -j _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Webobjects-dev mailing list      ([email protected])
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/webobjects-dev/kieran_lists%40mac.com
>> 
>> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to