further cleanups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@38719 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2015-06-29 12:07:00 +00:00
parent 08376ad7b9
commit 917150afd9
4 changed files with 34 additions and 28 deletions

View file

@ -6,6 +6,7 @@
Implement another missing convenience method.
Fix locking error when executing a batch.
Add -prepare:with: method for use by transactions.
Add -owner method to get a transaction's owner.
2015-06-27 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -1784,7 +1784,7 @@ SQLCLIENT_PRIVATE
@interface SQLTransaction : NSObject <NSCopying>
{
SQLCLIENT_PRIVATE
id _db;
id _owner;
NSMutableArray *_info;
unsigned _count;
BOOL _batch;
@ -1835,14 +1835,6 @@ SQLCLIENT_PRIVATE
*/
- (NSUInteger) count;
/**
* Returns the database client with which this instance operates.<br />
* 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.
* If any problem occurs, an NSException is raised, but the database connection
@ -1908,6 +1900,14 @@ SQLCLIENT_PRIVATE
*/
- (void) insertTransaction: (SQLTransaction*)trn atIndex: (unsigned)index;
/**
* Returns the database client with which this instance operates.<br />
* 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) owner;
/** Remove the index'th transaction or statement from the receiver.
*/
- (void) removeTransactionAtIndex: (unsigned)index;

View file

@ -72,7 +72,7 @@
"add:with:",
"append:",
"count",
"db",
"owner",
"execute",
"reset"
);

View file

@ -3118,7 +3118,7 @@ static int poolConnections = 0;
transaction = (SQLTransaction*)NSAllocateObject(self, 0,
NSDefaultMallocZone());
transaction->_db = [clientOrPool retain];
transaction->_owner = [clientOrPool retain];
transaction->_info = [NSMutableArray new];
transaction->_batch = isBatched;
transaction->_stop = stopOnFailure;
@ -3356,7 +3356,7 @@ static int poolConnections = 0;
NSMutableArray *p;
va_start (ap, stmt);
p = [_db prepare: stmt args: ap];
p = [_owner prepare: stmt args: ap];
va_end (ap);
[self _merge: p];
}
@ -3365,7 +3365,7 @@ static int poolConnections = 0;
{
NSMutableArray *p;
p = [_db prepare: stmt with: values];
p = [_owner prepare: stmt with: values];
[self _merge: p];
}
@ -3373,10 +3373,10 @@ static int poolConnections = 0;
{
if (other != nil && other->_count > 0)
{
if (NO == [_db isEqual: other->_db])
if (NO == [_owner isEqual: other->_owner])
{
[NSException raise: NSInvalidArgumentException
format: @"[%@-%@] database client missmatch",
format: @"[%@-%@] database owner missmatch",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
}
if (_merge > 0)
@ -3406,7 +3406,7 @@ static int poolConnections = 0;
SQLTransaction *c;
c = (SQLTransaction*)NSCopyObject(self, 0, z);
c->_db = [c->_db retain];
c->_owner = [c->_owner retain];
c->_info = [c->_info mutableCopy];
return c;
}
@ -3418,12 +3418,12 @@ static int poolConnections = 0;
- (id) db
{
return _db;
return _owner;
}
- (void) dealloc
{
[_db release]; _db = nil;
[_owner release]; _owner = nil;
[_info release]; _info = nil;
[super dealloc];
}
@ -3432,7 +3432,7 @@ static int poolConnections = 0;
{
return [NSString stringWithFormat: @"%@ with SQL '%@' for %@",
[super description],
(_count == 0 ? (id)@"" : (id)_info), _db];
(_count == 0 ? (id)@"" : (id)_info), _owner];
}
- (void) execute
@ -3445,14 +3445,14 @@ static int poolConnections = 0;
NSRecursiveLock *dbLock;
BOOL wrap;
if ([_db isKindOfClass: [SQLClientPool class]])
if ([_owner isKindOfClass: [SQLClientPool class]])
{
pool = (SQLClientPool*)_db;
pool = (SQLClientPool*)_owner;
db = [pool provideClient];
}
else
{
db = _db;
db = _owner;
}
dbLock = [db _lock];
@ -3537,14 +3537,14 @@ static int poolConnections = 0;
SQLClientPool *pool = nil;
SQLClient *db;
if ([_db isKindOfClass: [SQLClientPool class]])
if ([_owner isKindOfClass: [SQLClientPool class]])
{
pool = (SQLClientPool*)_db;
pool = (SQLClientPool*)_owner;
db = [pool provideClient];
}
else
{
db = _db;
db = _owner;
}
dbLock = [db _lock];
@ -3674,10 +3674,10 @@ static int poolConnections = 0;
format: @"[%@-%@] attempt to insert nil/empty transaction",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
}
if (NO == [_db isEqual: trn->_db])
if (NO == [_owner isEqual: trn->_owner])
{
[NSException raise: NSInvalidArgumentException
format: @"[%@-%@] database client missmatch",
format: @"[%@-%@] database owner missmatch",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
}
trn = [trn copy];
@ -3686,6 +3686,11 @@ static int poolConnections = 0;
[trn release];
}
- (id) owner
{
return _owner;
}
- (void) removeTransactionAtIndex: (unsigned)index
{
id o;
@ -3740,7 +3745,7 @@ static int poolConnections = 0;
o = [_info objectAtIndex: index];
if ([o isKindOfClass: NSArrayClass] == YES)
{
SQLTransaction *t = [[self db] transaction];
SQLTransaction *t = [[self owner] transaction];
[t addPrepared: o];
return t;