git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@39394 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2016-02-18 09:25:09 +00:00
parent dc0eb8406a
commit 1664989106
5 changed files with 1619 additions and 4021 deletions

View file

@ -1,3 +1,10 @@
2016-02-18 Richard Frith-Macdonald <rfm@gnu.org>
* configure.ac: get host and cpu with more recent gnustep-make
* configure: regenerate
* JDBC.m: Update for connection pools (bug #47178)
* testJDBC.m: get rid of compiler warnings
2015-07-22 Richard Frith-Macdonald <rfm@gnu.org> 2015-07-22 Richard Frith-Macdonald <rfm@gnu.org>
* Postgres.m: disconnect on fatal error, so we don't keep trying to * Postgres.m: disconnect on fatal error, so we don't keep trying to

55
JDBC.m
View file

@ -1521,7 +1521,7 @@ static int JDBCVARCHAR = 0;
transaction = (_JDBCTransaction*)NSAllocateObject([_JDBCTransaction class], 0, transaction = (_JDBCTransaction*)NSAllocateObject([_JDBCTransaction class], 0,
NSDefaultMallocZone()); NSDefaultMallocZone());
transaction->_db = [self retain]; transaction->_owner = [self retain];
transaction->_info = [NSMutableArray new]; transaction->_info = [NSMutableArray new];
transaction->_batch = YES; transaction->_batch = YES;
transaction->_stop = stopOnFailure; transaction->_stop = stopOnFailure;
@ -1680,7 +1680,7 @@ static int JDBCVARCHAR = 0;
transaction = (_JDBCTransaction*)NSAllocateObject([_JDBCTransaction class], 0, transaction = (_JDBCTransaction*)NSAllocateObject([_JDBCTransaction class], 0,
NSDefaultMallocZone()); NSDefaultMallocZone());
transaction->_db = [self retain]; transaction->_owner = [self retain];
transaction->_info = [NSMutableArray new]; transaction->_info = [NSMutableArray new];
return [(SQLTransaction*)transaction autorelease]; return [(SQLTransaction*)transaction autorelease];
} }
@ -1728,21 +1728,13 @@ static int JDBCVARCHAR = 0;
if (_count > 0) if (_count > 0)
{ {
NSAutoreleasePool *arp = [NSAutoreleasePool new]; NSAutoreleasePool *arp = [NSAutoreleasePool new];
SQLClientPool *pool;
SQLClient *db;
BOOL wrapped = NO; BOOL wrapped = NO;
BOOL batched = NO; BOOL batched = NO;
JNIEnv *env; JNIEnv *env;
JInfo *ji; JInfo *ji;
/*
* Ensure we have a working connection.
*/
if ([_db connect] == NO)
{
[NSException raise: SQLException
format: @"Unable to connect to '%@' to execute transaction %@",
[_db name], self];
}
env = SQLClientJNIEnv(); env = SQLClientJNIEnv();
if ((*env)->PushLocalFrame (env, 32) < 0) if ((*env)->PushLocalFrame (env, 32) < 0)
{ {
@ -1752,16 +1744,38 @@ static int JDBCVARCHAR = 0;
format: @"No java memory for execute"]; format: @"No java memory for execute"];
} }
ji = [(SQLClientJDBC*)_db _backendExtra]; if ([_owner isKindOfClass: [SQLClientPool class]])
{
pool = (SQLClientPool*)_owner;
db = [pool provideClient];
}
else
{
pool = nil;
db = _owner;
}
ji = [(SQLClientJDBC*)db _backendExtra];
NS_DURING NS_DURING
{ {
NSMutableArray *statements; NSMutableArray *statements;
unsigned numberOfStatements; unsigned numberOfStatements;
unsigned statement; unsigned statement;
NSTimeInterval _duration = [_db durationLogging]; NSTimeInterval _duration;
NSTimeInterval start = 0.0; NSTimeInterval start = 0.0;
/*
* Ensure we have a working connection.
*/
if ([db connect] == NO)
{
[NSException raise: SQLException
format: @"Unable to connect to '%@' to execute transaction %@",
[_owner name], self];
}
_duration = [db durationLogging];
statements = [NSMutableArray arrayWithCapacity: 100]; statements = [NSMutableArray arrayWithCapacity: 100];
[self _merge: statements]; [self _merge: statements];
numberOfStatements = [statements count]; numberOfStatements = [statements count];
@ -1771,7 +1785,7 @@ static int JDBCVARCHAR = 0;
start = GSTickerTimeNow(); start = GSTickerTimeNow();
} }
if ([_db isInTransaction] == NO) if ([db isInTransaction] == NO)
{ {
wrapped = YES; wrapped = YES;
} }
@ -1883,15 +1897,15 @@ static int JDBCVARCHAR = 0;
(*env)->PopLocalFrame (env, NULL); (*env)->PopLocalFrame (env, NULL);
_db->_lastOperation = GSTickerTimeNow(); db->_lastOperation = GSTickerTimeNow();
if (_duration >= 0) if (_duration >= 0)
{ {
NSTimeInterval d; NSTimeInterval d;
d = _db->_lastOperation - start; d = db->_lastOperation - start;
if (d >= _duration) if (d >= _duration)
{ {
[_db debug: @"Duration %g for transaction %@", [db debug: @"Duration %g for transaction %@",
d, statements]; d, statements];
} }
} }
@ -1913,6 +1927,11 @@ static int JDBCVARCHAR = 0;
} }
NS_ENDHANDLER NS_ENDHANDLER
if (nil != pool)
{
[pool swallowClient: db];
}
[arp release]; [arp release];
} }
} }

5567
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,11 @@ else
. $GNUSTEP_MAKEFILES/GNUstep.sh . $GNUSTEP_MAKEFILES/GNUstep.sh
fi fi
if test "x$GNUSTEP_HOST_OS" = "x"; then
GNUSTEP_HOST_OS=`gnustep-config --variable=GNUSTEP_HOST_OS`
GNUSTEP_HOST_CPU=`gnustep-config --variable=GNUSTEP_HOST_CPU`
fi
#-------------------------------------------------------------------- #--------------------------------------------------------------------
AC_ARG_WITH(additional-include, [ AC_ARG_WITH(additional-include, [
--with-additional-include=flags --with-additional-include=flags

View file

@ -125,7 +125,7 @@ main()
if (count == 0) if (count == 0)
{ {
[db commit]; [db commit];
sleep(1); [NSThread sleepForTimeInterval: 1.0];
[db begin]; [db begin];
records = [db query: @"SELECT * FROM Queue WHERE Consumer = ", records = [db query: @"SELECT * FROM Queue WHERE Consumer = ",
[db quote: name], [db quote: name],
@ -242,7 +242,7 @@ main()
r0 = [db cache: 1 query: @"select * from xxx", nil]; r0 = [db cache: 1 query: @"select * from xxx", nil];
r1 = [db cache: 1 query: @"select * from xxx", nil]; r1 = [db cache: 1 query: @"select * from xxx", nil];
NSCAssert([r0 lastObject] == [r1 lastObject], @"Cache failed"); NSCAssert([r0 lastObject] == [r1 lastObject], @"Cache failed");
sleep(2); [NSThread sleepForTimeInterval: 2.0];
records = [db cache: 1 query: @"select * from xxx", nil]; records = [db cache: 1 query: @"select * from xxx", nil];
NSCAssert([r0 lastObject] != [records lastObject], @"Lifetime failed"); NSCAssert([r0 lastObject] != [records lastObject], @"Lifetime failed");
@ -250,7 +250,7 @@ main()
if ([records count] != 3) if ([records count] != 3)
{ {
NSLog(@"Expected 3 records but got %u", [records count]); NSLog(@"Expected 3 records but got %"PRIuPTR, [records count]);
} }
else else
{ {