Author: rfm
Date: Wed Apr 1 13:32:49 2015
New Revision: 38447
URL: http://svn.gna.org/viewcvs/gnustep?rev=38447&view=rev
Log:
Threading/notification improvments
Modified:
libs/sqlclient/trunk/ChangeLog
libs/sqlclient/trunk/Postgres.m
libs/sqlclient/trunk/SQLClient.h
libs/sqlclient/trunk/SQLClient.m
libs/sqlclient/trunk/testPostgres.m
Modified: libs/sqlclient/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=38447&r1=38446&r2=38447&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog (original)
+++ libs/sqlclient/trunk/ChangeLog Wed Apr 1 13:32:49 2015
@@ -1,11 +1,28 @@
+2015-04-01 Richard Frith-Macdonald <[email protected]>
+
+ * SQLClient.h:
+ * Postgres.m:
+ Fixup notification posting to be asynchronous using the default
+ notification queue for the thread so that the notifications do
+ not get delivered while the query/statement at which they were
+ detected is still in progress.
+ Add method to explicitly grab/release the client for the current
+ thread.
+
2015-03-11 Richard Frith-Macdonald <[email protected]>
- * SQLClientPool.m: Fixup for ewxposing prepare method
+
+ * SQLClientPool.m: Fixup for exposing prepare method
* SQLClient.h:
* SQLClient.m:
* Postgres.m:
* testPostgres.m:
Add simple array support for char/varchar/text, integer/real,
- timestamp, bool and bytea.
+ timestamp, bool and bytea. When a query returns an array of
+ one of these types, the resulting object is an NSArray containing
+ the database array elements rather than an NSString containing the
+ string literal representation of the database array.
+ Also added a method to convert an NSArray to a string literal
+ representation of a database array.
2015-03-02 Richard Frith-Macdonald <[email protected]>
Modified: libs/sqlclient/trunk/Postgres.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=38447&r1=38446&r2=38447&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m (original)
+++ libs/sqlclient/trunk/Postgres.m Wed Apr 1 13:32:49 2015
@@ -35,6 +35,7 @@
#import <Foundation/NSFileHandle.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSNotification.h>
+#import <Foundation/NSNotificationQueue.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSMapTable.h>
#import <Foundation/NSLock.h>
@@ -279,8 +280,8 @@
- (void) _checkNotifications
{
- static NSNotificationCenter *nc;
- PGnotify *notify;
+ NSNotificationQueue *nq = nil;
+ PGnotify *notify;
while ((notify = PQnotifies(connection)) != 0)
{
@@ -328,11 +329,14 @@
userInfo: (NSDictionary*)userInfo];
[name release];
[userInfo release];
- if (nil == nc)
- {
- nc = [[NSNotificationCenter defaultCenter] retain];
- }
- [nc postNotification: n];
+
+ if (nil == nq)
+ {
+ nq = [NSNotificationQueue defaultQueue];
+ }
+ /* Post asynchronously
+ */
+ [nq enqueueNotification: n postingStyle: NSPostASAP];
}
NS_HANDLER
{
@@ -523,9 +527,9 @@
}
if ('\"' == *p)
{
- *p++ = '\0';
- }
- if (len == (p - start + 1))
+ *p = '\0';
+ }
+ if (len == (p - start))
{
v = [[NSString alloc] initWithUTF8String: start];
}
@@ -562,6 +566,7 @@
freeWhenDone: YES];
}
}
+ *p++ = '\"';
}
else
{
@@ -677,6 +682,7 @@
case 1002: // CHAR ARRAY
case 1009: // TEXT ARRAY
case 1015: // VARCHAR ARRAY
+ case 1263: // CSTRING ARRAY
if ('{' == *p)
{
NSMutableArray *a;
@@ -1212,7 +1218,7 @@
else if ([o isKindOfClass: [NSDate class]])
{
[s appendString: [self quote: (NSString*)o]];
- [s appendString: @"::timestamp"];
+ [s appendString: @"::timestamp with time zone"];
}
else if ([o isKindOfClass: [NSData class]])
{
Modified: libs/sqlclient/trunk/SQLClient.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38447&r1=38446&r2=38447&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h (original)
+++ libs/sqlclient/trunk/SQLClient.h Wed Apr 1 13:32:49 2015
@@ -488,6 +488,13 @@
*/
- (void) begin;
+/** This grabs the receiver for use by the current thread.<br />
+ * If limit is nil or in the past, makes a single immediate attempt.<br />
+ * Returns NO if it fails to obtain a lock by the specified date.<br />
+ * Must be matched by an -unlock if it succeeds.
+ */
+- (BOOL) lockBeforeDate: (NSDate*)limit;
+
/**
* <p>Build an sql query string using the supplied arguments.
* </p>
@@ -787,7 +794,12 @@
* YYYY-MM-DD hh:mm:ss.mmm ?ZZZZ<br />
* NSData objects are not quoted ... they must not appear in queries, and
* where used for insert/update operations, they need to be passed to the
- * -backendExecute: method unchanged.
+ * -backendExecute: method unchanged.<br />
+ * NSArray and NSSet objects are quoted as sets containing the quoted
+ * elements from the array/set. If you want to use SQL arrays (and your
+ * database backend supports it) you must explicitly use the
+ * -quoteArray:toString:quotingString: to convert an NSArray to a literal
+ * database array representation.
*/
- (NSString*) quote: (id)obj;
@@ -927,6 +939,10 @@
- (NSMutableArray*) simpleQuery: (NSString*)stmt
recordType: (id)rtype
listType: (id)ltype;
+
+/** Releases a lock previously obtained using -lockbeforeDate:
+ */
+- (void) unlock;
/**
* Return the database user for this instance (or nil).
@@ -1088,7 +1104,8 @@
* which don't support asynchronous notifications.<br />
* If a backend <em>does</em> support asynchronous notifications,
* it should do so by posting NSNotification instances to
- * [NSNotificationCenter defaultCenter] using the SQLClient instance as
+ * [NSNotificationQueue defaultQueue] with the posting style NSPostASAP
+ * (to post asynchronously) and using the SQLClient instance as
* the notification object and supplying any payload as a string using
* the 'Payload' key in the NSNotification userInfo dictionary.
* The userInfo dictionary should also contain a boolean (NSNumber) value,
@@ -1182,11 +1199,14 @@
* as an action by this SQLClient instance.<br />
* If the 'Payload' value is not nil, then it is a string providing extra
* information about the notification.<br />
- * NB. At the point when the observer is notified about an event the
- * database client object will be locked and may not be used to query
- * or modify the database (typically a database query will already be
- * in progress). The method handling the notification must therefore
- * handle any database operations in a later timeout.
+ * Notifications are posted asynchronously using the default notification
+ * queue for the current thread, so they should be delivered to the
+ * observer after the database statement in which they were detected
+ * has completed. However, delivery of the notification could still
+ * occur inside a transaction is the -begin and -commit statements
+ * are used. For this reason, observing code may want to use the
+ * -lockBeforeDate: -isInTransaction and -unlock methods to ensure
+ * that they don't interfere with ongoing transactions.
*/
- (void) addObserver: (id)anObserver
selector: (SEL)aSelector
Modified: libs/sqlclient/trunk/SQLClient.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=38447&r1=38446&r2=38447&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m (original)
+++ libs/sqlclient/trunk/SQLClient.m Wed Apr 1 13:32:49 2015
@@ -1339,6 +1339,15 @@
return [NSDate dateWithTimeIntervalSinceReferenceDate: _lastOperation];
}
return nil;
+}
+
+- (BOOL) lockBeforeDate: (NSDate*)limit
+{
+ if (nil == limit)
+ {
+ return [lock tryLock];
+ }
+ return [lock lockBeforeDate: limit];
}
- (SQLClient*) longestIdle: (SQLClient*)other
@@ -2013,6 +2022,11 @@
[self debug: @"%@", debug];
}
return result;
+}
+
+- (void) unlock
+{
+ [lock unlock];
}
- (NSString*) user
Modified: libs/sqlclient/trunk/testPostgres.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/testPostgres.m?rev=38447&r1=38446&r2=38447&view=diff
==============================================================================
--- libs/sqlclient/trunk/testPostgres.m (original)
+++ libs/sqlclient/trunk/testPostgres.m Wed Apr 1 13:32:49 2015
@@ -260,7 +260,7 @@
@"extra2 varchar[],"
@"extra3 bytea[],"
@"extra4 boolean[],"
- @"extra5 timestamp[]"
+ @"extra5 timestamp with time zone[]"
@")",
nil];
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs