Based on the tutorial for JAVA on the page : http://tutorials.jenkov.com/java-persistence/dao-manager.html,
I trying to implement the same concept with xCode for iOS.
The goal is to provide a DAOManager : a DAOCommand (defined as a protocol) + an implementation of his execute method. I could create a specific interface implementing the protocol, but as the mentioned example, I would like to implement the method when calling it. If I am right, it's possible to achieve that in objective-c using BLOCK.
Example of the java code provided on the mentioned Page :
public interface DaoCommand {
public Object execute(DaoManager daoManager);
}
Sample of code requesting a CRUD service :
DaoManager daoManager = daoFactory.createDaoManager();
Person person = (Person)
daoManager.executeAndClose(new DaoCommand(){
public Object execute(DaoManager manager){
return manager.getPersonDao().readPerson(666);
}
});
I tried to implement it in the following way : 1/ The DAOCommand :
@protocol IDaoCommand
- (id) executeUsingManager:(DAOManager*)pDAOManager;
@end
2/ My PoiCRUDService interface with a method getListOfPoi calling the DAOManager :
- (id) getListOfPoi {
DAOFactory* daoFactory = [[DAOFactory alloc] initWithOfflineMode:YES];
DAOManager* daoManager = [daoFactory createManager];
[daoManager executeAndCloseDaoCmdBlock:^(id<POIDAO> pPoiDAO) {
[pPoiDAO getListPoi];
}];
}
3/ My DAOManager with a method executeAndClose :
- (id) executeAndCloseDaoCmdBlock:(id(^)(id<IDaoCommand>))pDaoCmdBlock {
// Execute the query
//id returnObject = [[self getPoiDAO] getListPoi];
id returnObject = pDaoCmdBlock(self);
// Close the connection
[self.dataSource closeConnection];
return returnObject;
}
When I see my code, I don't see an creation of the DAOEntity (POIDAO). Actually, I have difficulties to see how to transpose the sample Java Code to xCode. Any idea on step and way to do ?
Thanks for any ideas or advices. St.