Author: rfm
Date: Thu Dec 11 11:47:12 2014
New Revision: 38248
URL: http://svn.gna.org/viewcvs/gnustep?rev=38248&view=rev
Log:
Convenience code ... allow a pool to be used as a client.
Modified:
libs/sqlclient/trunk/SQLClient.h
libs/sqlclient/trunk/SQLClientPool.m
Modified: libs/sqlclient/trunk/SQLClient.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38248&r1=38247&r2=38248&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h (original)
+++ libs/sqlclient/trunk/SQLClient.h Thu Dec 11 11:47:12 2014
@@ -1411,6 +1411,16 @@
* <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
{
Modified: libs/sqlclient/trunk/SQLClientPool.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=38248&r1=38247&r2=38248&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m (original)
+++ libs/sqlclient/trunk/SQLClientPool.m Thu Dec 11 11:47:12 2014
@@ -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
+
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs