IntroductionThis section contains common data access components. DetailsData access components include:
OxICDaoProxy samplesSuppose 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. StandaloneYou 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 containerThe 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. |