My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
DataComponents  
Data Access related components.
iPhone, iPad, Cocoa, CoreData, Data, DAO
Updated Feb 17, 2012 by lbrass...@gmail.com

Introduction

This section contains common data access components.

Details

Data access components include:

OxICDaoProxy samples

Suppose we have the following protocol:

@protocol PersonDao

- (NSArray*) findByName:(NSString*)namePart;
- (Person*) findJohnLennon;

- (id) insertNewObject;
- (void) delete:(id) anObject;
- (void) flush;

@end

The proxy allows mapping methods with queries, which will be executed using the findWithQuerySpec:andArguments: method int the OxICDaoProtocol class.

In the following examples, we'll show how to map the first two (findByName and findJohnLennon). Unmapped methods (insertNewObject, delete:, flush) are directly forwarded to OxICDaoProtocol object.

Standalone

You must initialize the object by passing the OxICDaoProtocol instance to be wrapped (realPersonDao in this example) and the protocol to be used in order to access the proxy.

OxICDaoProxy *proxy = [[OxICDaoProxy alloc] initWithDao:realPersonDao
                                            andProtocol:@protocol(PersonDao)];

Once the proxy is created, you can add query specifications to be binded with selectors:

[proxy addSelector:@"findJohnLennon"
     withQuerySpec:[OxICQuerySpec withFilter:@"name = 'John Lennon'"
                                     andUnique:YES]];

[proxy addSelector:@"findByName:"
     withQuerySpec:[OxICQuerySpec withFilter:@"name contains %@"]];

With container

The OxICDaoProxyFactoryObject class provides a factory for creating OxICDaoProxy instances from the IoC container.

[container addDefinition: [OxICObjectDefinition withName: @"personDao"
                                                andClass: @"OxICDaoProxyFactoryObject"
                                             andSingleton: FALSE
                                                  andLazy: FALSE
                                            andReferences: [NSDictionary dictionaryWithObjectsAndKeys:
                                                             @"realPersonDao", @"dao",
                                                             nil
                                                           ]
                                                andValues: [NSDictionary dictionaryWithObjectsAndKeys:
                                                             @protocol(PersonDao), @"protocol",
                                                             [NSDictionary dictionaryWithObjectsAndKeys:
                                                               [OxICQuerySpec withFilter:@"name = 'John Lennon'"
                                                                               andUnique:YES], 
                                                                              @"findJohnLennon",
                                                               [OxICQuerySpec withFilter:@"name contains %@"], 
                                                                              @"findByName:",
                                                               nil], @"querySpecs",
                                                               nil
                                                             ]
                                                           ]
];

In this example, the container must have a definition for a OxICDaoProtocol DAO called realPersonDao.


Sign in to add a comment
Powered by Google Project Hosting