diff options
author | Max <post@wickenrode.com> | 2015-11-20 04:48:50 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-11-20 04:48:50 +0100 |
commit | 8b2376dc47110530eeab8f61334ff46e28256045 (patch) | |
tree | 83170e070debcff4731af78a6120df2a5dad4f39 /Source | |
parent | 5568af642c2fc738f175e0be4729fd3e1fe2263a (diff) | |
download | sequelpro-8b2376dc47110530eeab8f61334ff46e28256045.tar.gz sequelpro-8b2376dc47110530eeab8f61334ff46e28256045.tar.bz2 sequelpro-8b2376dc47110530eeab8f61334ff46e28256045.zip |
Reorder some code to remove duplicate code and make leaking a NSAutoreleasePool more difficult
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPCSVExporter.m | 19 | ||||
-rw-r--r-- | Source/SPDotExporter.m | 13 | ||||
-rw-r--r-- | Source/SPExporter.h | 5 | ||||
-rw-r--r-- | Source/SPExporter.m | 24 | ||||
-rw-r--r-- | Source/SPHTMLExporter.m | 11 | ||||
-rw-r--r-- | Source/SPPDFExporter.m | 11 | ||||
-rw-r--r-- | Source/SPSQLExporter.m | 18 | ||||
-rw-r--r-- | Source/SPXMLExporter.m | 13 |
8 files changed, 35 insertions, 79 deletions
diff --git a/Source/SPCSVExporter.m b/Source/SPCSVExporter.m index 5fb6f664..964f8f6f 100644 --- a/Source/SPCSVExporter.m +++ b/Source/SPCSVExporter.m @@ -68,13 +68,10 @@ } /** - * Start the CSV export process. This method is automatically called when an instance of this class - * is placed on an NSOperationQueue. Do not call it directly as there is no manual multithreading. + * Start the CSV export process. */ -- (void)main -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - +- (void)exportOperation +{ NSMutableString *csvString = [NSMutableString string]; NSMutableString *csvCellString = [NSMutableString string]; @@ -96,7 +93,6 @@ if ((![self csvTableName] && ![self csvDataArray]) || ([[self csvTableName] isEqualToString:@""] && [[self csvDataArray] count] == 0)) { - [pool release]; return; } @@ -105,7 +101,6 @@ (![self csvEscapeString]) || (![self csvLineEndingString])) { - [pool release]; return; } @@ -114,7 +109,6 @@ ([[self csvEscapeString] isEqualToString:@""]) || ([[self csvLineEndingString] isEqualToString:@""])) { - [pool release]; return; } @@ -233,8 +227,7 @@ } [csvExportPool release]; - [pool release]; - + return; } @@ -266,8 +259,7 @@ // Check for cancellation flag if ([self isCancelled]) { [csvExportPool release]; - [pool release]; - + return; } @@ -408,7 +400,6 @@ [delegate performSelectorOnMainThread:@selector(csvExportProcessComplete:) withObject:self waitUntilDone:NO]; [csvExportPool release]; - [pool release]; } #pragma mark - diff --git a/Source/SPDotExporter.m b/Source/SPDotExporter.m index bb95da6b..3e9213da 100644 --- a/Source/SPDotExporter.m +++ b/Source/SPDotExporter.m @@ -65,19 +65,12 @@ return self; } -/** - * Start the Dot schema export process. This method is automatically called when an instance of this class - * is placed on an NSOperationQueue. Do not call it directly as there is no manual multithreading. - */ -- (void)main +- (void)exportOperation { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSMutableString *metaString = [NSMutableString string]; // Check that we have all the required info before starting the export if ((![self dotExportTables]) || (![self dotTableData]) || ([[self dotExportTables] count] == 0)) { - [pool release]; return; } @@ -120,7 +113,6 @@ // Check for cancellation flag if ([self isCancelled]) { [fkInfo release]; - [pool release]; return; } @@ -171,7 +163,6 @@ // Check for cancellation flag if ([self isCancelled]) { [fkInfo release]; - [pool release]; return; } @@ -225,8 +216,6 @@ // Inform the delegate that the export process is complete [delegate performSelectorOnMainThread:@selector(dotExportProcessComplete:) withObject:self waitUntilDone:NO]; - - [pool release]; } #pragma mark - diff --git a/Source/SPExporter.h b/Source/SPExporter.h index 1ddb9a69..a2a19020 100644 --- a/Source/SPExporter.h +++ b/Source/SPExporter.h @@ -130,4 +130,9 @@ - (void)setExportOutputCompressFile:(BOOL)compress; +/** + * This is the method you should override in every concrete exporter implementation. + */ +- (void)exportOperation; + @end diff --git a/Source/SPExporter.m b/Source/SPExporter.m index dfd5b4fa..adfe0545 100644 --- a/Source/SPExporter.m +++ b/Source/SPExporter.m @@ -67,11 +67,31 @@ } /** - * Override NSOperation's main() method. This method should never be called as all subclasses should override it. + * Override NSOperation's main() method. + * This method only creates an autoreleasepool and calls exportOperation */ - (void)main { - [NSException raise:NSInternalInconsistencyException format:@"Cannot call NSOperation's main() method in SPExpoter, must be overriden in a subclass. See SPExporter.h"]; + NSAutoreleasePool *pool = nil; + @try { + pool = [[NSAutoreleasePool alloc] init]; + + [self exportOperation]; + } + @catch(NSException *e) { + [[NSApp onMainThread] reportException:e]; // will be caught by FeedbackReporter + } + @finally { + [pool release]; + } +} + +/** + * This method should never be called as all subclasses should override it. + */ +- (void)exportOperation +{ + [NSException raise:NSInternalInconsistencyException format:@"Cannot call %s, must be overriden in a subclass. See SPExporter.h",__PRETTY_FUNCTION__]; } /** diff --git a/Source/SPHTMLExporter.m b/Source/SPHTMLExporter.m index 9bcc6616..f82ed472 100644 --- a/Source/SPHTMLExporter.m +++ b/Source/SPHTMLExporter.m @@ -53,15 +53,4 @@ return self; } -/** - * Start the HTML export process. This method is automatically called when an instance of this class - * is placed on an NSOperationQueue. Do not call it directly as there is no manual multithreading. - */ -- (void)main -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - [pool release]; -} - @end diff --git a/Source/SPPDFExporter.m b/Source/SPPDFExporter.m index 9d92dc7f..0eda99b1 100644 --- a/Source/SPPDFExporter.m +++ b/Source/SPPDFExporter.m @@ -53,15 +53,4 @@ return self; } -/** - * Start the PDF export process. This method is automatically called when an instance of this class - * is placed on an NSOperationQueue. Do not call it directly as there is no manual multithreading. - */ -- (void)main -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - [pool release]; -} - @end diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m index c575156d..2fc581b0 100644 --- a/Source/SPSQLExporter.m +++ b/Source/SPSQLExporter.m @@ -84,13 +84,8 @@ return self; } -/** - * Start the SQL export process. This method is automatically called when an instance of this class - * is placed on an NSOperationQueue. Do not call it directly as there is no manual multithreading. - */ -- (void)main +- (void)exportOperation { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; sqlTableDataInstance = [[[SPTableData alloc] init] autorelease]; [sqlTableDataInstance setConnection:connection]; @@ -128,7 +123,6 @@ { [errors release]; [sqlString release]; - [pool release]; return; } @@ -150,7 +144,6 @@ if ([self isCancelled]) { [errors release]; [sqlString release]; - [pool release]; return; } @@ -207,7 +200,6 @@ if ([self isCancelled]) { [errors release]; [sqlString release]; - [pool release]; return; } @@ -383,7 +375,6 @@ [sqlExportPool release]; [errors release]; [sqlString release]; - [pool release]; free(useRawDataForColumnAtIndex); free(useRawHexDataForColumnAtIndex); @@ -550,7 +541,6 @@ if ([self isCancelled]) { [errors release]; [sqlString release]; - [pool release]; return; } @@ -598,7 +588,6 @@ if ([self isCancelled]) { [errors release]; [sqlString release]; - [pool release]; return; } @@ -619,7 +608,6 @@ if ([self isCancelled]) { [errors release]; [sqlString release]; - [pool release]; return; } @@ -651,7 +639,6 @@ if ([self isCancelled]) { [errors release]; [sqlString release]; - [pool release]; return; } @@ -667,7 +654,6 @@ [proceduresList release]; [errors release]; [sqlString release]; - [pool release]; return; } @@ -796,8 +782,6 @@ // Inform the delegate that the export process is complete [delegate performSelectorOnMainThread:@selector(sqlExportProcessComplete:) withObject:self waitUntilDone:NO]; - - [pool release]; } /** diff --git a/Source/SPXMLExporter.m b/Source/SPXMLExporter.m index dd4e9223..39e89287 100644 --- a/Source/SPXMLExporter.m +++ b/Source/SPXMLExporter.m @@ -63,14 +63,8 @@ return self; } -/** - * Start the XML export process. This method is automatically called when an instance of this class - * is placed on an NSOperationQueue. Do not call it directly as there is no manual multithreading. - */ -- (void)main +- (void)exportOperation { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - BOOL isTableExport = NO; NSArray *xmlRow = nil; @@ -96,7 +90,6 @@ (([self xmlFormat] == SPXMLExportMySQLFormat) && ((![self xmlOutputIncludeStructure]) && (![self xmlOutputIncludeContent]))) || (([self xmlFormat] == SPXMLExportPlainFormat) && (![self xmlNULLString]))) { - [pool release]; return; } @@ -213,7 +206,6 @@ } [xmlExportPool release]; - [pool release]; return; } @@ -245,7 +237,6 @@ } [xmlExportPool release]; - [pool release]; return; } @@ -350,8 +341,6 @@ // Inform the delegate that the export process is complete [delegate performSelectorOnMainThread:@selector(xmlExportProcessComplete:) withObject:self waitUntilDone:NO]; - - [pool release]; } #pragma mark - |