From 85d4c823527236bca756dba3d430e840fd131454 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 2 Dec 2010 01:54:11 +0000 Subject: - Fix graph language/DOT export hanging - this addresses Issue #916. - Fix graph language/DOT export progress bars and feedback - Fix graph language/DOT export of table relations to correctly link tables based on foreign keys/constraints --- Source/SPDotExporter.m | 69 ++++++++++++++++++++++-------------------- Source/SPDotExporterDelegate.m | 20 ++++++------ Source/SPDotExporterProtocol.h | 13 ++++---- 3 files changed, 54 insertions(+), 48 deletions(-) (limited to 'Source') diff --git a/Source/SPDotExporter.m b/Source/SPDotExporter.m index 9db34a7c..85b497e9 100644 --- a/Source/SPDotExporter.m +++ b/Source/SPDotExporter.m @@ -72,7 +72,7 @@ [pool release]; return; } - + // Inform the delegate that the export process is about to begin [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBegin:) withObject:self waitUntilDone:NO]; @@ -106,6 +106,7 @@ // Process the tables for (NSInteger i = 0; i < [[self dotExportTables] count]; i++) { + // Check for cancellation flag if ([self isCancelled]) { [fkInfo release]; @@ -120,7 +121,7 @@ [self setDotExportCurrentTable:tableName]; // Inform the delegate that we are about to start fetcihing data for the current table - [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBeginFetchingData:) withObject:self waitUntilDone:NO]; + [[delegate onMainThread] dotExportProcessWillBeginFetchingData:self forTableWithIndex:i]; NSString *hdrColor = @"#DDDDDD"; @@ -134,12 +135,12 @@ [metaString appendString:@"\t\t\t\n"]; [metaString appendFormat:@"\t\t\t\n", hdrColor, tableName]; - // Get the column info - NSArray *columnInfo = [tableInfo objectForKey:@"columns"]; + // Retrieve the column definitions for the current table + NSArray *tableColumns = [tableInfo objectForKey:@"columns"]; - for (NSDictionary* item in columnInfo) + for (NSDictionary *aColumn in tableColumns) { - [metaString appendFormat:@"\t\t\t\n", [item objectForKey:@"name"], [item objectForKey:@"name"], [item objectForKey:@"type"]]; + [metaString appendFormat:@"\t\t\t\n", [aColumn objectForKey:@"name"], [aColumn objectForKey:@"name"], [aColumn objectForKey:@"type"]]; } [metaString appendString:@"\t\t\t
%@
%@:%@
%@:%@
>\n"]; @@ -148,34 +149,38 @@ [[self exportOutputFile] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; - // see about relations - columnInfo = [tableInfo objectForKey:@"constraints"]; - - NSString *ccol = NSArrayObjectAtIndex(columnInfo, 0); - for (NSDictionary* item in columnInfo) - { - // Check for cancellation flag - if ([self isCancelled]) { - [fkInfo release]; - [pool release]; - return; - } - - // Get the column references. Currently the columns themselves are an array, - // while reference columns and tables are comma separated if there are more than - // one. Only use the first of each for the time being. - NSArray *ccols = [item objectForKey:@"columns"]; - NSString *rcol = [item objectForKey:@"ref_columns"]; - - NSString *extra = @""; - - if ([ccols count] > 1) { - extra = @" [ arrowhead=crow, arrowtail=odiamond ]"; - rcol = NSArrayObjectAtIndex([rcol componentsSeparatedByString:@","], 0); + // Check if any relations are available for the table + NSArray *tableConstraints = [tableInfo objectForKey:@"constraints"]; + if ([tableConstraints count]) { + for (NSDictionary* aConstraint in tableConstraints) { + + // Check for cancellation flag + if ([self isCancelled]) { + [fkInfo release]; + [pool release]; + return; + } + + // Get the column references. Currently the columns themselves are an array, + // while reference columns and tables are comma separated if there are more than + // one. Only use the first of each for the time being. + NSArray *originColumns = [aConstraint objectForKey:@"columns"]; + NSArray *referenceColumns = [[aConstraint objectForKey:@"ref_columns"] componentsSeparatedByString:@","]; + + NSString *extra = @""; + + if ([originColumns count] > 1) { + extra = @" [ arrowhead=crow, arrowtail=odiamond ]"; + } + + [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@ %@", tableName, [originColumns objectAtIndex:0], [aConstraint objectForKey:@"ref_table"], [referenceColumns objectAtIndex:0], extra]]; } - - [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@ %@", tableName, ccol, [item objectForKey:@"ref_table"], rcol, extra]]; } + + // Update progress + NSInteger progress = (i * ([self exportMaxProgress] / [[self dotExportTables] count])); + [self setExportProgressValue:progress]; + [delegate performSelectorOnMainThread:@selector(dotExportProcessProgressUpdated:) withObject:self waitUntilDone:NO]; } // Inform the delegate that we are about to start fetching relations data for the current table diff --git a/Source/SPDotExporterDelegate.m b/Source/SPDotExporterDelegate.m index ceb24354..2d1e4b46 100644 --- a/Source/SPDotExporterDelegate.m +++ b/Source/SPDotExporterDelegate.m @@ -39,6 +39,8 @@ [[exportProgressTitle onMainThread] displayIfNeeded]; [[exportProgressText onMainThread] displayIfNeeded]; + [[exportProgressIndicator onMainThread] stopAnimation:self]; + [[exportProgressIndicator onMainThread] setIndeterminate:NO]; } /** @@ -63,25 +65,20 @@ */ - (void)dotExportProcessProgressUpdated:(SPDotExporter *)exporter { - + [exportProgressIndicator setDoubleValue:[exporter exportProgressValue]]; } /** * */ -- (void)dotExportProcessWillBeginFetchingData:(SPDotExporter *)exporter +- (void)dotExportProcessWillBeginFetchingData:(SPDotExporter *)exporter forTableWithIndex:(NSUInteger)tableIndex { // Update the current table export index - currentTableExportIndex = (exportTableCount - [exporters count]); + currentTableExportIndex = tableIndex; - [[exportProgressText onMainThread] setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Table %lu of %lu (%@): Fetching data...", @"export label showing that the app is fetching data for a specific table"), currentTableExportIndex, exportTableCount, [exporter dotExportCurrentTable]]]; + [exportProgressText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Table %lu of %lu (%@): Fetching data...", @"export label showing that the app is fetching data for a specific table"), currentTableExportIndex, exportTableCount, [exporter dotExportCurrentTable]]]; - [[exportProgressText onMainThread] displayIfNeeded]; - - [[exportProgressIndicator onMainThread] stopAnimation:self]; - [[exportProgressIndicator onMainThread] setUsesThreadedAnimation:NO]; - [[exportProgressIndicator onMainThread] setIndeterminate:NO]; - [[exportProgressIndicator onMainThread] setDoubleValue:0]; + [exportProgressText displayIfNeeded]; } /** @@ -92,6 +89,9 @@ [[exportProgressText onMainThread] setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Table %lu of %lu (%@): Fetching relations data...", @"export label showing app is fetching relations data for a specific table"), currentTableExportIndex, exportTableCount, [exporter dotExportCurrentTable]]]; [[exportProgressText onMainThread] displayIfNeeded]; + [[exportProgressIndicator onMainThread] setIndeterminate:YES]; + [[exportProgressIndicator onMainThread] setUsesThreadedAnimation:YES]; + [[exportProgressIndicator onMainThread] startAnimation:self]; } @end diff --git a/Source/SPDotExporterProtocol.h b/Source/SPDotExporterProtocol.h index 5d2c3db3..f7cc0dec 100644 --- a/Source/SPDotExporterProtocol.h +++ b/Source/SPDotExporterProtocol.h @@ -37,35 +37,36 @@ /** * Called when the dot export process is about to begin. * - * @param SPDotExpoter The expoter calling the method. + * @param SPDotExporter The exporter calling the method. */ - (void)dotExportProcessWillBegin:(SPDotExporter *)exporter; /** * Called when the dot export process is complete. * - * @param SPDotExpoter The expoter calling the method. + * @param SPDotExporter The exporter calling the method. */ - (void)dotExportProcessComplete:(SPDotExporter *)exporter; /** * Called when the progress of the dot export process is updated. * - * @param SPDotExpoter The expoter calling the method. + * @param SPDotExporter The exporter calling the method. */ - (void)dotExportProcessProgressUpdated:(SPDotExporter *)exporter; /** * Called when the dot export process is about to begin fetching data from the database. * - * @param SPDotExpoter The expoter calling the method. + * @param SPDotExporter The exporter calling the method. + * @param NSUInteger The index of the table being processed. */ -- (void)dotExportProcessWillBeginFetchingData:(SPDotExporter *)exporter; +- (void)dotExportProcessWillBeginFetchingData:(SPDotExporter *)exporter forTableWithIndex:(NSUInteger)tableIndex; /** * Called when the dot export process is about to begin writing data to disk. * - * @param SPDotExpoter The expoter calling the method. + * @param SPDotExporter The exporter calling the method. */ - (void)dotExportProcessWillBeginFetchingRelationsData:(SPDotExporter *)exporter; -- cgit v1.2.3