Author: rfm
Date: Fri Jun 26 14:06:13 2015
New Revision: 38694
URL: http://svn.gna.org/viewcvs/gnustep?rev=38694&view=rev
Log:
client name settings
Modified:
libs/sqlclient/trunk/ChangeLog
libs/sqlclient/trunk/SQLClient.h
libs/sqlclient/trunk/SQLClient.m
libs/sqlclient/trunk/SQLClientPool.m
Modified: libs/sqlclient/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=38694&r1=38693&r2=38694&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog (original)
+++ libs/sqlclient/trunk/ChangeLog Fri Jun 26 14:06:13 2015
@@ -1,7 +1,17 @@
+2015-06-26 Richard Frith-Macdonald <[email protected]>
+
+ * SQLClient.h:
+ * SQLClient.m:
+ * SQLClientPool.m:
+ Implement -transaction method for client pools so that we can build
+ a transaction which, when executed, will use any available client
+ from the pool.
+ Support setting of the client name for clients in a pool.
+
2015-06-25 Niels Grewe <[email protected]>
* SQLClient.[hm]: Add an accessor method to obtain the SQLClientPool
- object owning a specific SQLClient.
+ object owning a specific SQLClient.
2015-06-25 Richard Frith-Macdonald <[email protected]>
Modified: libs/sqlclient/trunk/SQLClient.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38694&r1=38693&r2=38694&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h (original)
+++ libs/sqlclient/trunk/SQLClient.h Fri Jun 26 14:06:13 2015
@@ -925,6 +925,14 @@
- (void) rollback;
/**
+ * Set the client name for this client.<br />
+ * If this is not set (or is set to nul) a globally unique string is used.<br
/>
+ * NB. Setting the name may not be reflected in the database server until
+ * the client disconnects and reconnects.
+ */
+- (void) setClientName: (NSString*)s;
+
+/**
* Set the database host/name for this object.<br />
* This is called automatically to configure the connection ...
* you normally shouldn't need to call it yourself.
@@ -1343,8 +1351,7 @@
*/
- (void) singletons: (NSMutableArray*)records;
-/**
- * Creates and returns an autoreleased SQLTransaction instance which will
+/** Creates and returns an autoreleased SQLTransaction instance which will
* use the receiver as the database connection to perform transactions.
*/
- (SQLTransaction*) transaction;
@@ -1637,10 +1644,19 @@
*/
- (void) setCache: (GSCache*)aCache;
-/**
- * Sets the cache thread for all the clients in the pool.
+/** Sets the cache thread for all the clients in the pool.
*/
- (void) setCacheThread: (NSThread*)aThread;
+
+/** Set the client name for all the client connections in the pool.<br />
+ * If the argument is not nil, the name of each client in the pool
+ * is set to the argument with a suffix of '(x)' where x is the number
+ * of the client within the pool, otherwise (nil argument) each client
+ * is allocated a globally unique string as its name.<br />
+ * NB. This setting does not apply to new connections added when the pool
+ * maximum size is increased.
+ */
+- (void) setClientName: (NSString*)s;
/** Set the debugging level for all clients in the pool.
*/
@@ -1685,6 +1701,11 @@
* Returns YES if the supplied client was from the pool, NO otherwise.
*/
- (BOOL) swallowClient: (SQLClient*)client;
+
+/** Creates and returns an autoreleased SQLTransaction instance which will
+ * use the receiver as the database connection to perform transactions.
+ */
+- (SQLTransaction*) transaction;
@end
@@ -1750,7 +1771,7 @@
@interface SQLTransaction : NSObject <NSCopying>
{
SQLCLIENT_PRIVATE
- SQLClient *_db;
+ id _db;
NSMutableArray *_info;
unsigned _count;
BOOL _batch;
@@ -1803,9 +1824,11 @@
/**
* Returns the database client with which this instance operates.<br />
- * This client is retained by the transaction.
- */
-- (SQLClient*) db;
+ * This client is retained by the transaction.<br />
+ * If the transaction was created by/for an SQLClientPool, this method
+ * returns that pool rather than an individual client.
+ */
+- (id) db;
/**
* <p>Performs any statements added to the transaction as a single operation.
Modified: libs/sqlclient/trunk/SQLClient.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=38694&r1=38693&r2=38694&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m (original)
+++ libs/sqlclient/trunk/SQLClient.m Fri Jun 26 14:06:13 2015
@@ -88,6 +88,9 @@
@interface SQLClientPool (Swallow)
- (BOOL) _swallowClient: (SQLClient*)client withRetain: (BOOL)shouldRetain;
@end
+@interface SQLTransaction (Creation)
++ (SQLTransaction*) _transactionUsing: (id)clientOrPool;
+@end
@implementation SQLRecordKeys
@@ -1088,7 +1091,16 @@
- (NSString*) clientName
{
- return _client;
+ NSString *s;
+
+ [lock lock];
+ if (nil == _client)
+ {
+ _client = [[[NSProcessInfo processInfo] globallyUniqueString] retain];
+ }
+ s = [_client retain];
+ [lock unlock];
+ return [s autorelease];
}
- (void) commit
@@ -1888,6 +1900,13 @@
[localException raise];
}
NS_ENDHANDLER
+}
+
+- (void) setClientName: (NSString*)s
+{
+ [lock lock];
+ ASSIGNCOPY(_client, s);
+ [lock unlock];
}
- (void) setDatabase: (NSString*)s
@@ -1949,8 +1968,11 @@
s = [s copy];
[_name release];
_name = s;
- [_client release];
- _client = [[[NSProcessInfo processInfo] globallyUniqueString]
retain];
+ if (nil == _client)
+ {
+ _client
+ = [[[NSProcessInfo processInfo] globallyUniqueString] retain];
+ }
if (nil == _pool && _name != nil)
{
NSMapInsert(clientsMap, (void*)_name, (void*)self);
@@ -2842,15 +2864,9 @@
- (SQLTransaction*) transaction
{
- SQLTransaction *transaction;
-
- transaction = (SQLTransaction*)NSAllocateObject([SQLTransaction class], 0,
- NSDefaultMallocZone());
-
- transaction->_db = [self retain];
- transaction->_info = [NSMutableArray new];
- return [(SQLTransaction*)transaction autorelease];
-}
+ return [SQLTransaction _transactionUsing: self];
+}
+
@end
@@ -3107,6 +3123,18 @@
@end
@implementation SQLTransaction
+
++ (SQLTransaction*) _transactionUsing: (id)clientOrPool
+{
+ SQLTransaction *transaction;
+
+ transaction = (SQLTransaction*)NSAllocateObject(self, 0,
+ NSDefaultMallocZone());
+
+ transaction->_db = [clientOrPool retain];
+ transaction->_info = [NSMutableArray new];
+ return [transaction autorelease];
+}
- (void) _addSQL: (NSMutableString*)sql andArgs: (NSMutableArray*)args
{
@@ -3399,7 +3427,7 @@
return [_info count];
}
-- (SQLClient*) db
+- (id) db
{
return _db;
}
@@ -3423,11 +3451,24 @@
if (_count > 0)
{
NSMutableArray *info = nil;
- NSRecursiveLock *dbLock = [_db _lock];
+ SQLClientPool *pool = nil;
+ SQLClient *db;
+ NSRecursiveLock *dbLock;
BOOL wrap;
+ if ([_db isKindOfClass: [SQLClientPool class]])
+ {
+ pool = (SQLClientPool*)_db;
+ db = [pool provideClient];
+ }
+ else
+ {
+ db = _db;
+ }
+
+ dbLock = [db _lock];
[dbLock lock];
- wrap = [_db isInTransaction] ? NO : YES;
+ wrap = [db isInTransaction] ? NO : YES;
NS_DURING
{
NSMutableString *sql;
@@ -3454,9 +3495,13 @@
[sql appendString: @"commit;"];
}
- [_db simpleExecute: info];
+ [db simpleExecute: info];
[info release]; info = nil;
[dbLock unlock];
+ if (nil != pool)
+ {
+ [pool swallowClient: db];
+ }
}
NS_HANDLER
{
@@ -3467,16 +3512,20 @@
{
NS_DURING
{
- [_db simpleExecute: rollbackStatement];
+ [db simpleExecute: rollbackStatement];
}
NS_HANDLER
{
- [_db disconnect];
+ [db disconnect];
NSLog(@"Disconnected due to failed rollback after %@", e);
}
NS_ENDHANDLER
}
[dbLock unlock];
+ if (nil != pool)
+ {
+ [pool swallowClient: db];
+ }
[e raise];
}
NS_ENDHANDLER
@@ -3496,7 +3545,20 @@
if (_count > 0)
{
NSRecursiveLock *dbLock = [_db _lock];
-
+ SQLClientPool *pool = nil;
+ SQLClient *db;
+
+ if ([_db isKindOfClass: [SQLClientPool class]])
+ {
+ pool = (SQLClientPool*)_db;
+ db = [pool provideClient];
+ }
+ else
+ {
+ db = _db;
+ }
+
+ dbLock = [db _lock];
[dbLock lock];
NS_DURING
{
@@ -3505,9 +3567,9 @@
}
NS_HANDLER
{
- if (log == YES || [_db debugging] > 0)
+ if (log == YES || [db debugging] > 0)
{
- [_db debug: @"Initial failure executing batch %@: %@",
+ [db debug: @"Initial failure executing batch %@: %@",
self, localException];
}
if (_batch == YES)
@@ -3536,7 +3598,7 @@
*/
if (wrapper == nil)
{
- wrapper = [_db transaction];
+ wrapper = [db transaction];
}
[wrapper reset];
[wrapper addPrepared: o];
@@ -3550,9 +3612,9 @@
{
[failures addPrepared: o];
}
- if (log == YES || [_db debugging] > 0)
+ if (log == YES || [db debugging] > 0)
{
- [_db debug:
+ [db debug:
@"Failure of %d executing batch %@: %@",
i, self, localException];
}
@@ -3601,6 +3663,10 @@
}
NS_ENDHANDLER
[dbLock unlock];
+ if (nil != pool)
+ {
+ [pool swallowClient: db];
+ }
}
return executed;
}
Modified: libs/sqlclient/trunk/SQLClientPool.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=38694&r1=38693&r2=38694&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m (original)
+++ libs/sqlclient/trunk/SQLClientPool.m Fri Jun 26 14:06:13 2015
@@ -59,6 +59,10 @@
- (void) _lock;
- (NSString*) _rc: (SQLClient*)o;
- (void) _unlock;
+@end
+
+@interface SQLTransaction (Creation)
++ (SQLTransaction*) _transactionUsing: (id)clientOrPool;
@end
@implementation SQLClientPool
@@ -724,6 +728,36 @@
{
return [self _swallowClient: client withRetain: YES];
}
+
+- (void) setClientName: (NSString*)s
+{
+ unsigned int index;
+
+ [lock lock];
+ for (index = 0; index < max; index++)
+ {
+ SQLClient *client = c[index];
+
+ if (nil == s)
+ {
+ [client setClientName: s];
+ }
+ else
+ {
+ NSString *n;
+
+ n = [s stringByAppendingFormat: @" (%u)", index];
+ [client setClientName: n];
+ }
+ }
+ [lock unlock];
+}
+
+- (SQLTransaction*) transaction
+{
+ return [SQLTransaction _transactionUsing: self];
+}
+
@end
@implementation SQLClientPool (Private)
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs