[baseten-users] BXDatabaseContext usage
Réjean Lamy
rejean.lamy at mac.com
Tue May 19 16:20:53 EEST 2009
I have reduced the problem to its simplest expression.
Anybody can easily try this with the BaseTen CarLot example:
1- Remove the BXDatabaseContext object from the nib
2- Add the following code "MyAppController" to the project
//MyAppController.h
#import <Cocoa/Cocoa.h>
#import <BaseTen/BaseTen.h>
#import <BaseTenAppKit/BaseTenAppKit.h>
@interface MyAppController : NSObject {
IBOutlet BXDatabaseContext *databaseContext;
}
@end
//MyAppController.m
#import "MyAppController.h"
@implementation MyAppController
- (id) init
{
self = [super init];
if (self != nil) {
NSURL* databaseURI = [NSURL URLWithString: @"pgsql://user:password@localhost/cars
"];
databaseContext = [[BXDatabaseContext alloc] initWithDatabaseURI:
databaseURI];
[databaseContext setAutocommits:YES];
[databaseContext connectSync:NULL];
}
return self;
}
@end
3- Add an NSObject to the nib and change its class to "MyAppController"
4- Bind the BXSynchronizedArrayController's "Database Context"
parameter to the MyAppController's "databaseContext" IBOutlet
Run CarLot and observe a first strange result (No more automatic fetch
on startup).
Also, try to comment the line
//[databaseContext connectSync:NULL];
Connect or no connect seems to have no effect at all, with same result.
Is it legal to instantiate a BXDatabaseContext this way and pass the
pointer via IBOutlet to a BXSynchronizeArrayControllers located in a
nib ?
If not, what is the right way to use BXDatabaseContext other than
dropping its IB object in each nib ?
RL
Le 09-05-18 à 17:54, Réjean Lamy a écrit :
> Same result :(
>
> One of the strange thing I observed is about fetch.
> When I used a BXDatabaseContext object directly in the nib, a table
> is populated with DB data automatically when the window is showed.
>
> But when I use a BXDatabaseContext instance in the main controller
> and passing the ctx to the nib, the table is _not_ populated with DB
> data.
> In that case I must use a Fetch button.
>
> Strange because, in either case, the "Fetch On Connect" was always
> checked on the BX Array Controller driving the NSTable.
>
>
> Le 09-05-18 à 14:19, Daniel Brajkovic a écrit :
>
>> What I have done, following the examples in Cocoa Programming for
>> Mac OS X by Hillegass, is to create a "main controller" that
>> creates the ctx context. And in that controller, create controllers
>> for each of the Nibs and pass ctx to each of those controllers.
>>
>> I believe that if you drop the app delegate in each of the other
>> Nibs, you are actually creating new instances of the app delegate
>> class. That might explain your "weird" problems.
>>
>>
>> On May 18, 2009, at 12:53 PM, Réjean Lamy wrote:
>>
>>> That was one solution I have tried but with no success ( i.e.
>>> resulting with weirds problems with fetch, add/remove to
>>> relationships etc..):
>>>
>>> BXDatabaseContext instance the app delegate class with the
>>> resulting ctx made available to nibs via and IBOutlet that can be
>>> accessed in each nib File's Owner.
>>> The resulting ctx avaible in each nib is connected to the BX Sync
>>> Array controller using the "databaseContext" binding parameter.
>>>
>>> Rejean Lamy
>>>
>>>
>>> Le 09-05-18 à 13:15, Daniel Brajkovic a écrit :
>>>
>>>> Can't you simply instantiate the database controller in an object
>>>> shared by your nibs such as an appController class?
>>>>
>>>> Daniel Brajkovic
>>>>
>>>> Sent from iPhone.
>>>>
>>>> On May 18, 2009, at 12:10 PM, Réjean Lamy <rejean.lamy at mac.com>
>>>> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> I would like to know how to use a _single_ BXDatabaseContext
>>>>> object connected with multiple BXSynchronizedArrayControllers
>>>>> located in many nib files.
>>>>>
>>>>> My app is made of several nib files, each one handling different
>>>>> window with tables, buttons etc..
>>>>> Each nib file include the needed BXSynchronizedArrayControllers
>>>>> and actually I must also include a BXDatabaseContext object in
>>>>> each nib file.
>>>>>
>>>>> The problem is that all of these BXDatabaseContext must be
>>>>> changed manually to the correct URI. Also, it will be more
>>>>> efficient to my app handling a single point of connection to the
>>>>> db.
>>>>>
>>>>> Thanks.
>>>>>
>>>>> Rejean Lamy
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> baseten-users mailing list
>>>>> baseten-users at lists.basetenframework.org
>>>>> http://lists.basetenframework.org/mailman/listinfo/baseten-users
>>>>
>>>> _______________________________________________
>>>> baseten-users mailing list
>>>> baseten-users at lists.basetenframework.org
>>>> http://lists.basetenframework.org/mailman/listinfo/baseten-users
>>>
>>>
>>> _______________________________________________
>>> baseten-users mailing list
>>> baseten-users at lists.basetenframework.org
>>> http://lists.basetenframework.org/mailman/listinfo/baseten-users
>>
>> _______________________________________________
>> baseten-users mailing list
>> baseten-users at lists.basetenframework.org
>> http://lists.basetenframework.org/mailman/listinfo/baseten-users
>
>
> _______________________________________________
> baseten-users mailing list
> baseten-users at lists.basetenframework.org
> http://lists.basetenframework.org/mailman/listinfo/baseten-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basetenframework.org/pipermail/baseten-users/attachments/20090519/3ad986a4/attachment-0001.htm>
More information about the baseten-users
mailing list