diff --git a/SOPE/GDLContentStore/ChangeLog b/SOPE/GDLContentStore/ChangeLog index 7d7d44dbb..75341dc1c 100644 --- a/SOPE/GDLContentStore/ChangeLog +++ b/SOPE/GDLContentStore/ChangeLog @@ -1,3 +1,17 @@ +2010-06-11 Wolfgang Sourdeau + + * GCSFolderManager.m + (_reallyCreateFolderWithName:andFolderType:andType:andChannel:atPath:): + we now make use of the new classes described below. + + * GCSSpecialQueries.m (-[EOAdaptorChannel specialQueries]): new + category method that returns the proper GCSSpecialQueries instance + based on the channel class. + + * GCSSpecialQueries.[hm]: new module providing the + "GCSSpecialQueries" cluster class that implements + SQL queries that are specific to each SQL implementation. + 2010-04-20 Wolfgang Sourdeau * EOAdaptorChannel+GCS.m (-tableExistsWithName:): cleaned method diff --git a/SOPE/GDLContentStore/EOAdaptorChannel+GCS.h b/SOPE/GDLContentStore/EOAdaptorChannel+GCS.h index 4adaacc2f..9c316bfc1 100644 --- a/SOPE/GDLContentStore/EOAdaptorChannel+GCS.h +++ b/SOPE/GDLContentStore/EOAdaptorChannel+GCS.h @@ -24,13 +24,6 @@ #include -@protocol GCSEOAdaptorChannel - -- (NSException *) createGCSFolderTableWithName: (NSString *) tableName; -- (NSException *) createGCSFolderACLTableWithName: (NSString *) tableName; - -@end - @interface EOAdaptorChannel(GCS) - (BOOL) tableExistsWithName: (NSString *) _tableName; diff --git a/SOPE/GDLContentStore/GCSFolderManager.m b/SOPE/GDLContentStore/GCSFolderManager.m index ffe0fafab..34e3f2ca5 100644 --- a/SOPE/GDLContentStore/GCSFolderManager.m +++ b/SOPE/GDLContentStore/GCSFolderManager.m @@ -41,6 +41,7 @@ #import "GCSChannelManager.h" #import "GCSFolderType.h" #import "GCSFolder.h" +#import "GCSSpecialQueries.h" #import "NSURL+GCS.h" #import "EOAdaptorChannel+GCS.h" @@ -710,14 +711,15 @@ static NSCharacterSet *asciiAlphaNumericCS = nil; - (NSException *) _reallyCreateFolderWithName: (NSString *) folderName andFolderType: (NSString *) folderType andType: (GCSFolderType *) ftype - andChannel: (EOAdaptorChannel - *) channel + andChannel: (EOAdaptorChannel *) channel atPath: (NSString *) path { NSException *error; - NSString *baseURL, *tableName, *quickTableName, *aclTableName, *sql; + NSString *baseURL, *tableName, *quickTableName, *aclTableName, *createQuery, + *sql; EOAdaptorContext *aContext; NSMutableArray *paths; + GCSSpecialQueries *specialQuery; paths = [NSMutableArray arrayWithArray: [path componentsSeparatedByString: @"/"]]; @@ -752,13 +754,19 @@ static NSCharacterSet *asciiAlphaNumericCS = nil; error = [channel evaluateExpressionX: sql]; if (!error) { - error = [channel createGCSFolderTableWithName: tableName]; + specialQuery = [channel specialQueries]; + createQuery = [specialQuery createFolderTableWithName: tableName]; + error = [channel evaluateExpressionX: createQuery]; if (!error) { sql = [ftype sqlQuickCreateWithTableName: quickTableName]; error = [channel evaluateExpressionX: sql]; if (!error) - error = [channel createGCSFolderACLTableWithName: aclTableName]; + { + createQuery = [specialQuery + createFolderACLTableWithName: aclTableName]; + error = [channel evaluateExpressionX: createQuery]; + } } } @@ -776,7 +784,7 @@ static NSCharacterSet *asciiAlphaNumericCS = nil; { // TBD: would be best to perform all operations as a single SQL statement. GCSFolderType *ftype; - EOAdaptorChannel *channel; + EOAdaptorChannel *channel; NSException *error; // TBD: fix SQL injection issue! diff --git a/SOPE/GDLContentStore/GCSSpecialQueries.h b/SOPE/GDLContentStore/GCSSpecialQueries.h new file mode 100644 index 000000000..48674e02b --- /dev/null +++ b/SOPE/GDLContentStore/GCSSpecialQueries.h @@ -0,0 +1,45 @@ +/* GCSSpecialQueries.h - this file is part of $PROJECT_NAME_HERE$ + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef GCSSPECIALQUERIES_H +#define GCSSPECIALQUERIES_H + +#import + +#import + +@class NSString; + +@interface GCSSpecialQueries : NSObject + +- (NSString *) createFolderTableWithName: (NSString *) tableName; +- (NSString *) createFolderACLTableWithName: (NSString *) tableName; + +@end + +@interface EOAdaptorChannel (GCSSpecialQueries) + +- (GCSSpecialQueries *) specialQueries; + +@end + +#endif /* GCSSPECIALQUERIES_H */ diff --git a/SOPE/GDLContentStore/GCSSpecialQueries.m b/SOPE/GDLContentStore/GCSSpecialQueries.m new file mode 100644 index 000000000..24092ebc2 --- /dev/null +++ b/SOPE/GDLContentStore/GCSSpecialQueries.m @@ -0,0 +1,186 @@ +/* GCSSpecialQueries.m - this file is part of SOGo + * + * Copyright (C) 2010 Inverse inc. + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import + +#import "GCSSpecialQueries.h" + +@interface GCSPostgreSQLSpecialQueries : GCSSpecialQueries +@end + +@interface GCSMySQLSpecialQueries : GCSSpecialQueries +@end + +@interface GCSOracleSpecialQueries : GCSSpecialQueries +@end + +@implementation EOAdaptorChannel (GCSSpecialQueries) + +- (GCSSpecialQueries *) specialQueries +{ + static NSMutableDictionary *queries = nil; + GCSSpecialQueries *specialQueries; + NSString *specialQueriesClass, *thisClass; + + if (!queries) + { + queries = [NSMutableDictionary new]; + [queries setObject: @"GCSPostgreSQLSpecialQueries" + forKey: @"PostgreSQL72Channel"]; + [queries setObject: @"GCSMySQLSpecialQueries" + forKey: @"MySQL4Channel"]; + [queries setObject: @"GCSOracleSpecialQueries" + forKey: @"OracleAdaptorChannel"]; + } + + thisClass = NSStringFromClass ([self class]); + specialQueriesClass = [queries objectForKey: thisClass]; + if (specialQueriesClass) + { + specialQueries = [NSClassFromString (specialQueriesClass) new]; + [specialQueries autorelease]; + } + else + { + specialQueries = nil; + [self errorWithFormat: + @"No GCSSpecialQueries subclass defined for channel class '%@'", + thisClass]; + } + + return specialQueries; +} + +@end + +@implementation GCSSpecialQueries + +- (NSString *) createFolderTableWithName: (NSString *) tableName +{ + [self subclassResponsibility: _cmd]; + + return nil; +} + +- (NSString *) createFolderACLTableWithName: (NSString *) tableName +{ + [self subclassResponsibility: _cmd]; + + return nil; +} + +@end + +@implementation GCSPostgreSQLSpecialQueries + +- (NSString *) createFolderTableWithName: (NSString *) tableName +{ + static NSString *sqlFolderFormat + = (@"CREATE TABLE %@ (\n" + @" c_name VARCHAR (255) NOT NULL PRIMARY KEY,\n" + @" c_content VARCHAR (100000) NOT NULL,\n" + @" c_creationdate INT4 NOT NULL,\n" + @" c_lastmodified INT4 NOT NULL,\n" + @" c_version INT4 NOT NULL,\n" + @" c_deleted INT4 NULL\n" + @")"); + + return [NSString stringWithFormat: sqlFolderFormat, tableName]; +} + +- (NSString *) createFolderACLTableWithName: (NSString *) tableName +{ + static NSString *sqlFolderACLFormat + = (@"CREATE TABLE %@ (\n" + @" c_uid VARCHAR (255) NOT NULL,\n" + @" c_object VARCHAR (255) NOT NULL,\n" + @" c_role VARCHAR (80) NOT NULL\n" + @")"); + + return [NSString stringWithFormat: sqlFolderACLFormat, tableName]; +} + +@end + +@implementation GCSMySQLSpecialQueries + +- (NSString *) createFolderTableWithName: (NSString *) tableName +{ + static NSString *sqlFolderFormat + = (@"CREATE TABLE %@ (\n" + @" c_name VARCHAR (255) NOT NULL PRIMARY KEY,\n" + @" c_content VARCHAR (100000) NOT NULL,\n" + @" c_creationdate INT NOT NULL,\n" + @" c_lastmodified INT NOT NULL,\n" + @" c_version INT NOT NULL,\n" + @" c_deleted INT NULL\n" + @")"); + + return [NSString stringWithFormat: sqlFolderFormat, tableName]; +} + +- (NSString *) createFolderACLTableWithName: (NSString *) tableName +{ + static NSString *sqlFolderACLFormat + = (@"CREATE TABLE %@ (\n" + @" c_uid VARCHAR (255) NOT NULL,\n" + @" c_object VARCHAR (255) NOT NULL,\n" + @" c_role VARCHAR (80) NOT NULL\n" + @")"); + + return [NSString stringWithFormat: sqlFolderACLFormat, tableName]; +} + +@end + +@implementation GCSOracleSpecialQueries + +- (NSString *) createFolderTableWithName: (NSString *) tableName +{ + static NSString *sqlFolderFormat + = (@"CREATE TABLE %@ (\n" + @" c_name VARCHAR2 (255) NOT NULL PRIMARY KEY,\n" + @" c_content CLOB NOT NULL,\n" + @" c_creationdate INTEGER NOT NULL,\n" + @" c_lastmodified INTEGER NOT NULL,\n" + @" c_version INTEGER NOT NULL,\n" + @" c_deleted INTEGER DEFAULT 0 NOT NULL\n" + @")"); + + return [NSString stringWithFormat: sqlFolderFormat, tableName]; +} + +- (NSString *) createFolderACLTableWithName: (NSString *) tableName +{ + static NSString *sqlFolderACLFormat + = (@"CREATE TABLE %@ (\n" + @" c_uid VARCHAR (255) NOT NULL,\n" + @" c_object VARCHAR (255) NOT NULL,\n" + @" c_role VARCHAR (80) NOT NULL\n" + @")"); + return [NSString stringWithFormat: sqlFolderACLFormat, tableName]; +} + +@end diff --git a/SOPE/GDLContentStore/GNUmakefile b/SOPE/GDLContentStore/GNUmakefile index 48730f644..7963a46d2 100644 --- a/SOPE/GDLContentStore/GNUmakefile +++ b/SOPE/GDLContentStore/GNUmakefile @@ -31,6 +31,7 @@ libGDLContentStore_HEADER_FILES += \ GCSFolderType.h \ GCSChannelManager.h \ GCSFieldExtractor.h \ + GCSSpecialQueries.h \ GCSStringFormatter.h \ libGDLContentStore_OBJC_FILES += \ @@ -45,6 +46,7 @@ libGDLContentStore_OBJC_FILES += \ GCSFolderType.m \ GCSChannelManager.m \ GCSFieldExtractor.m \ + GCSSpecialQueries.m \ GCSStringFormatter.m \ # framework support diff --git a/SOPE/sope-patchset-r1664.diff b/SOPE/sope-patchset-r1664.diff index 1954e86b9..683c7c3aa 100644 --- a/SOPE/sope-patchset-r1664.diff +++ b/SOPE/sope-patchset-r1664.diff @@ -391,94 +391,6 @@ Index: sope-ldap/NGLdap/NGLdapConnection.h /* query parameters */ - (void)setQueryTimeLimit:(NSTimeInterval)_timeLimit; -Index: sope-gdl1/PostgreSQL/PostgreSQL72Channel.m -=================================================================== ---- sope-gdl1/PostgreSQL/PostgreSQL72Channel.m (revision 1664) -+++ sope-gdl1/PostgreSQL/PostgreSQL72Channel.m (working copy) -@@ -713,6 +713,39 @@ - return ms; - } - -+/* GCSEOAdaptorChannel protocol */ -+static NSString *sqlFolderFormat = (@"CREATE TABLE %@ (\n" \ -+ @" c_name VARCHAR (255) NOT NULL PRIMARY KEY,\n" -+ @" c_content VARCHAR (100000) NOT NULL,\n" -+ @" c_creationdate INT4 NOT NULL,\n" -+ @" c_lastmodified INT4 NOT NULL,\n" -+ @" c_version INT4 NOT NULL,\n" -+ @" c_deleted INT4 NULL\n" -+ @")"); -+static NSString *sqlFolderACLFormat = (@"CREATE TABLE %@ (\n" \ -+ @" c_uid VARCHAR (255) NOT NULL,\n" -+ @" c_object VARCHAR (255) NOT NULL,\n" -+ @" c_role VARCHAR (80) NOT NULL\n" -+ @")"); -+ -+- (NSException *) createGCSFolderTableWithName: (NSString *) tableName -+{ -+ NSString *sql; -+ -+ sql = [NSString stringWithFormat: sqlFolderFormat, tableName]; -+ -+ return [self evaluateExpressionX: sql]; -+} -+ -+- (NSException *) createGCSFolderACLTableWithName: (NSString *) tableName -+{ -+ NSString *sql; -+ -+ sql = [NSString stringWithFormat: sqlFolderACLFormat, tableName]; -+ -+ return [self evaluateExpressionX: sql]; -+} -+ - @end /* PostgreSQL72Channel */ - - @implementation PostgreSQL72Channel(PrimaryKeyGeneration) -Index: sope-gdl1/MySQL/MySQL4Channel.m -=================================================================== ---- sope-gdl1/MySQL/MySQL4Channel.m (revision 1664) -+++ sope-gdl1/MySQL/MySQL4Channel.m (working copy) -@@ -755,6 +755,39 @@ - return pkey; - } - -+/* GCSEOAdaptorChannel protocol */ -+static NSString *sqlFolderFormat = (@"CREATE TABLE %@ (\n" \ -+ @" c_name VARCHAR (255) NOT NULL PRIMARY KEY,\n" -+ @" c_content VARCHAR (100000) NOT NULL,\n" -+ @" c_creationdate INT NOT NULL,\n" -+ @" c_lastmodified INT NOT NULL,\n" -+ @" c_version INT NOT NULL,\n" -+ @" c_deleted INT NULL\n" -+ @")"); -+static NSString *sqlFolderACLFormat = (@"CREATE TABLE %@ (\n" \ -+ @" c_uid VARCHAR (255) NOT NULL,\n" -+ @" c_object VARCHAR (255) NOT NULL,\n" -+ @" c_role VARCHAR (80) NOT NULL\n" -+ @")"); -+ -+- (NSException *) createGCSFolderTableWithName: (NSString *) tableName -+{ -+ NSString *sql; -+ -+ sql = [NSString stringWithFormat: sqlFolderFormat, tableName]; -+ -+ return [self evaluateExpressionX: sql]; -+} -+ -+- (NSException *) createGCSFolderACLTableWithName: (NSString *) tableName -+{ -+ NSString *sql; -+ -+ sql = [NSString stringWithFormat: sqlFolderACLFormat, tableName]; -+ -+ return [self evaluateExpressionX: sql]; -+} -+ - @end /* MySQL4Channel */ - - void __link_MySQL4Channel() { Index: sope-gdl1/Oracle8/ChangeLog =================================================================== --- sope-gdl1/Oracle8/ChangeLog (revision 1664) @@ -790,26 +702,44 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m status = OCIStmtFetch2(_current_stm, _oci_err, (ub4)1, (ub4)OCI_FETCH_NEXT, (sb4)0, (ub4)OCI_DEFAULT); if (status == OCI_NO_DATA) -@@ -609,7 +706,7 @@ +@@ -607,37 +704,4 @@ + return _oci_ctx; + } - /* GCSEOAdaptorChannel protocol */ - static NSString *sqlFolderFormat = (@"CREATE TABLE %@ (\n" \ +-/* GCSEOAdaptorChannel protocol */ +-static NSString *sqlFolderFormat = (@"CREATE TABLE %@ (\n" \ - @" c_name VARCHAR2 (256) NOT NULL,\n" -+ @" c_name VARCHAR2 (255) NOT NULL PRIMARY KEY,\n" - @" c_content CLOB NOT NULL,\n" - @" c_creationdate INTEGER NOT NULL,\n" - @" c_lastmodified INTEGER NOT NULL,\n" -@@ -617,8 +714,8 @@ - @" c_deleted INTEGER DEFAULT 0 NOT NULL\n" - @")"); - static NSString *sqlFolderACLFormat = (@"CREATE TABLE %@ (\n" \ +- @" c_content CLOB NOT NULL,\n" +- @" c_creationdate INTEGER NOT NULL,\n" +- @" c_lastmodified INTEGER NOT NULL,\n" +- @" c_version INTEGER NOT NULL,\n" +- @" c_deleted INTEGER DEFAULT 0 NOT NULL\n" +- @")"); +-static NSString *sqlFolderACLFormat = (@"CREATE TABLE %@ (\n" \ - @" c_uid VARCHAR (256) NOT NULL,\n" - @" c_object VARCHAR (256) NOT NULL,\n" -+ @" c_uid VARCHAR (255) NOT NULL,\n" -+ @" c_object VARCHAR (255) NOT NULL,\n" - @" c_role VARCHAR (80) NOT NULL\n" - @")"); - +- @" c_role VARCHAR (80) NOT NULL\n" +- @")"); +- +-- (NSException *) createGCSFolderTableWithName: (NSString *) tableName +-{ +- NSString *sql; +- +- sql = [NSString stringWithFormat: sqlFolderFormat, tableName]; +- +- return [self evaluateExpressionX: sql]; +-} +- +-- (NSException *) createGCSFolderACLTableWithName: (NSString *) tableName +-{ +- NSString *sql; +- +- sql = [NSString stringWithFormat: sqlFolderACLFormat, tableName]; +- +- return [self evaluateExpressionX: sql]; +-} +- + @end Index: sope-gdl1/Oracle8/OracleAdaptorChannelController.m =================================================================== --- sope-gdl1/Oracle8/OracleAdaptorChannelController.m (revision 1664)