Convenience code ... allow a pool to be used as a client.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38248 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2014-12-11 10:47:12 +00:00
parent 0a2267cfba
commit d985eb2650
2 changed files with 68 additions and 0 deletions

View file

@ -1411,6 +1411,16 @@ SQLCLIENT_PRIVATE
* <p>All clients in the pool share the same cache object, so query results
* cached by one client will be available to other clients in the pool.
* </p>
* <p>As a convenience, an SQLClientPool instance acts as a proxy for the
* clients it contains, so you may (where it makes sense) send the same
* messages to a pool that you would send to an individual client, and the
* pool will temporarily allocate one of its clients to handle it.<br />
* In this case the client will be returned to the pool immediately
* after the message has been handled (and subsequent messages may go
* to a different client), so you can't change settings or send any other
* method which would be required to be followed up by another message to
* the same client.
* </p>
*/
@interface SQLClientPool : NSObject
{

View file

@ -29,6 +29,7 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSException.h>
#import <Foundation/NSInvocation.h>
#import <Foundation/NSLock.h>
#import <Foundation/NSString.h>
@ -541,3 +542,60 @@
@end
@implementation SQLClientPool (Proxying)
static BOOL
selIsBad(SEL aSelector)
{
const char *n = sel_getName(aSelector);
if (strncmp(n, "set", 3) == 0)
{
return YES;
}
if (strncmp(n, "backend", 7) == 0)
{
return YES;
}
if (strcmp(n, "begin") == 0)
{
return YES;
}
return NO;
}
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
SQLClient *db;
db = [self provideClient];
[anInvocation invokeWithTarget: db];
[self swallowClient: db];
}
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
{
NSMethodSignature *methodSig;
methodSig = [super methodSignatureForSelector: aSelector];
if (nil == methodSig && 0 != c && NO == selIsBad(aSelector))
{
methodSig = [c[0] methodSignatureForSelector: aSelector];
}
return methodSig;
}
- (BOOL) respondsToSelector: (SEL)aSelector
{
BOOL result;
result = [super respondsToSelector: aSelector];
if (NO == result && 0 != c && NO == selIsBad(aSelector))
{
result = [c[0] respondsToSelector: aSelector];
}
return result;
}
@end