From 4de95f82669135f01807ebcb0128f721cc820e68 Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 1 Mar 2005 15:30:39 +0000 Subject: [PATCH] work on storing content and quick in one table git-svn-id: http://svn.opengroupware.org/SOGo/trunk@616 d1b88da0-ebda-0310-925b-ed51d893ca5b --- OGoContentStore/ChangeLog | 5 + OGoContentStore/OCSChannelManager.h | 3 +- OGoContentStore/OCSChannelManager.m | 3 +- OGoContentStore/OCSFolder.h | 7 ++ OGoContentStore/OCSFolder.m | 136 +++++++++++++++++----------- OGoContentStore/OCSFolderManager.h | 3 +- OGoContentStore/Version | 2 +- 7 files changed, 101 insertions(+), 58 deletions(-) diff --git a/OGoContentStore/ChangeLog b/OGoContentStore/ChangeLog index 53fc28e8..40b29c3b 100644 --- a/OGoContentStore/ChangeLog +++ b/OGoContentStore/ChangeLog @@ -1,3 +1,8 @@ +2005-03-01 Helge Hess + + * OCSFolder.m: added support for storing content and quick info in + the same table (untested) (v0.9.21) + 2005-02-21 Helge Hess * v0.9.20 diff --git a/OGoContentStore/OCSChannelManager.h b/OGoContentStore/OCSChannelManager.h index c888ec35..ed956639 100644 --- a/OGoContentStore/OCSChannelManager.h +++ b/OGoContentStore/OCSChannelManager.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2004 SKYRIX Software AG + Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __OGoContentStore_OCSChannelManager_H__ #define __OGoContentStore_OCSChannelManager_H__ diff --git a/OGoContentStore/OCSChannelManager.m b/OGoContentStore/OCSChannelManager.m index 6c4bfa3f..02c813c7 100644 --- a/OGoContentStore/OCSChannelManager.m +++ b/OGoContentStore/OCSChannelManager.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2004 SKYRIX Software AG + Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "OCSChannelManager.h" #include "NSURL+OCS.h" diff --git a/OGoContentStore/OCSFolder.h b/OGoContentStore/OCSFolder.h index 89000bad..162c7078 100644 --- a/OGoContentStore/OCSFolder.h +++ b/OGoContentStore/OCSFolder.h @@ -42,6 +42,12 @@ NSURL *location; NSURL *quickLocation; NSString *folderTypeName; + + struct { + int requiresFolderSelect:1; + int sameTableForQuick:1; + int reserved:30; + } ofFlags; } - (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId @@ -63,6 +69,7 @@ - (NSString *)storeTableName; - (NSString *)quickTableName; +- (BOOL)isQuickInfoStoredInContentTable; /* connection */ diff --git a/OGoContentStore/OCSFolder.m b/OGoContentStore/OCSFolder.m index b0f92c94..be5470a6 100644 --- a/OGoContentStore/OCSFolder.m +++ b/OGoContentStore/OCSFolder.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2004 SKYRIX Software AG + Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "OCSFolder.h" #include "OCSFolderManager.h" @@ -60,6 +59,13 @@ static OCSStringFormatter *stringFormatter = nil; location:(NSURL *)_loc quickLocation:(NSURL *)_qloc folderManager:(OCSFolderManager *)_fm { + if (![_loc isNotNull]) { + [self logWithFormat:@"ERROR(%s): missing quicktable parameter!", + __PRETTY_FUNCTION__]; + [self release]; + return nil; + } + if ((self = [super init])) { self->folderManager = [_fm retain]; self->folderInfo = [_ftype retain]; @@ -68,8 +74,12 @@ static OCSStringFormatter *stringFormatter = nil; self->folderName = [[_path lastPathComponent] copy]; self->path = [_path copy]; self->location = [_loc retain]; - self->quickLocation = [_qloc retain]; + self->quickLocation = _qloc ? [_qloc retain] : [_loc retain]; self->folderTypeName = [_ftname copy]; + + self->ofFlags.requiresFolderSelect = 0; + self->ofFlags.sameTableForQuick = + [self->location isEqualTo:self->quickLocation] ? 1 : 0; } return self; } @@ -130,6 +140,10 @@ static OCSStringFormatter *stringFormatter = nil; return [[self quickLocation] ocsTableName]; } +- (BOOL)isQuickInfoStoredInContentTable { + return self->ofFlags.sameTableForQuick ? YES : NO; +} + /* channels */ - (EOAdaptorChannel *)acquireStoreChannel { @@ -431,12 +445,17 @@ static OCSStringFormatter *stringFormatter = nil; /* make content row */ contentRow = [NSMutableDictionary dictionaryWithCapacity:16]; + + if (self->ofFlags.sameTableForQuick) + [contentRow addEntriesFromDictionary:quickRow]; + [contentRow setObject:_name forKey:@"c_name"]; if (isNewRecord) [contentRow setObject:now forKey:@"c_creationdate"]; [contentRow setObject:now forKey:@"c_lastmodified"]; if (isNewRecord) [contentRow setObject:[NSNumber numberWithInt:0] forKey:@"c_version"]; else { + // TODO: increase version? [contentRow setObject:[NSNumber numberWithInt:[storedVersion intValue]] forKey:@"c_version"]; } @@ -448,59 +467,71 @@ static OCSStringFormatter *stringFormatter = nil; [self logWithFormat:@"ERROR(%s): could not open storage channel!"]; return nil; } - if ((quickChannel = [self acquireQuickChannel]) == nil) { - [self logWithFormat:@"ERROR(%s): could not open quick channel!"]; - [self releaseChannel:storeChannel]; - return nil; + if (!self->ofFlags.sameTableForQuick) { + if ((quickChannel = [self acquireQuickChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open quick channel!"]; + [self releaseChannel:storeChannel]; + return nil; + } } + + /* generate SQL */ - // TODO: gen SQL, execute in transactions + qsql = nil; if (isNewRecord) { /* insert */ - qsql = [self _generateInsertStatementForRow:quickRow - tableName:[self quickTableName]]; - bsql = [self _generateInsertStatementForRow:contentRow - tableName:[self storeTableName]]; - - if ((error = [storeChannel evaluateExpressionX:bsql]) != nil) { - [self logWithFormat:@"ERROR(%s): cannot insert content '%@': %@", - __PRETTY_FUNCTION__, bsql, error]; - } - else if ((error = [quickChannel evaluateExpressionX:qsql]) != nil) { - NSString *delsql; - NSException *delErr; - - [self logWithFormat:@"ERROR(%s): cannot insert quick '%@': %@", - __PRETTY_FUNCTION__, qsql, error]; - - delsql = [@"DELETE FROM " stringByAppendingString:[self storeTableName]]; - delsql = [delsql stringByAppendingString:@" WHERE c_name="]; - delsql = [delsql stringByAppendingString:[self _formatRowValue:_name]]; - if ((delErr = [storeChannel evaluateExpressionX:delsql]) != nil) { - [self logWithFormat: - @"ERROR(%s): cannot delete content '%@' after quick-fail: %@", - __PRETTY_FUNCTION__, delsql, error]; - } + if (!self->ofFlags.sameTableForQuick) { + qsql = [self _generateInsertStatementForRow:quickRow + tableName:[self quickTableName]]; } + bsql = [self _generateInsertStatementForRow:contentRow + tableName:[self storeTableName]]; } - else { /* update */ - qsql = [self _generateUpdateStatementForRow:quickRow - tableName:[self quickTableName] - whereColumn:@"c_name" isEqualTo:_name]; + else { + if (!self->ofFlags.sameTableForQuick) { + qsql = [self _generateUpdateStatementForRow:quickRow + tableName:[self quickTableName] + whereColumn:@"c_name" isEqualTo:_name]; + } bsql = [self _generateUpdateStatementForRow:contentRow tableName:[self storeTableName] whereColumn:@"c_name" isEqualTo:_name]; - if ((error = [storeChannel evaluateExpressionX:bsql]) != nil) { - [self logWithFormat:@"ERROR(%s): cannot update content '%@': %@", - __PRETTY_FUNCTION__, bsql, error]; - } - else if ((error = [quickChannel evaluateExpressionX:qsql]) != nil) { - [self logWithFormat:@"ERROR(%s): cannot update quick '%@': %@", - __PRETTY_FUNCTION__, qsql, error]; + } + + /* execute */ + // TODO: execute in transactions + + if ((error = [storeChannel evaluateExpressionX:bsql]) != nil) { + [self logWithFormat:@"ERROR(%s): cannot %s content '%@': %@", + __PRETTY_FUNCTION__, isNewRecord ? "insert" : "update", bsql, error]; + } + + if (error == nil && qsql != nil) { + if ((error = [quickChannel evaluateExpressionX:qsql]) != nil) { + NSString *delsql; + NSException *delErr; + + [self logWithFormat:@"ERROR(%s): cannot %s quick '%@': %@", + __PRETTY_FUNCTION__, isNewRecord ? "insert" : "update", + qsql, error]; + + if (isNewRecord) { + /* insert in quick failed, so delete in content table */ + + delsql = [@"DELETE FROM " stringByAppendingString: + [self storeTableName]]; + delsql = [delsql stringByAppendingString:@" WHERE c_name="]; + delsql = [delsql stringByAppendingString:[self _formatRowValue:_name]]; + if ((delErr = [storeChannel evaluateExpressionX:delsql]) != nil) { + [self logWithFormat: + @"ERROR(%s): could not delete content '%@' after quick-fail:" + @" %@", __PRETTY_FUNCTION__, delsql, error]; + } + } } } [self releaseChannel:storeChannel]; - [self releaseChannel:quickChannel]; + if (!self->ofFlags.sameTableForQuick) [self releaseChannel:quickChannel]; return error; } @@ -526,12 +557,14 @@ static OCSStringFormatter *stringFormatter = nil; [self logWithFormat:@"ERROR(%s): could not open storage channel!"]; return nil; } - if ((quickChannel = [self acquireQuickChannel]) == nil) { - [self logWithFormat:@"ERROR(%s): could not open quick channel!"]; - [self releaseChannel:storeChannel]; - return nil; + if (!self->ofFlags.sameTableForQuick) { + if ((quickChannel = [self acquireQuickChannel]) == nil) { + [self logWithFormat:@"ERROR(%s): could not open quick channel!"]; + [self releaseChannel:storeChannel]; + return nil; + } } - + /* delete rows */ delsql = [@"DELETE FROM " stringByAppendingString:[self storeTableName]]; @@ -542,7 +575,7 @@ static OCSStringFormatter *stringFormatter = nil; @"ERROR(%s): cannot delete content '%@': %@", __PRETTY_FUNCTION__, delsql, error]; } - else { + else if (!self->ofFlags.sameTableForQuick) { /* content row deleted, now delete the quick row */ delsql = [@"DELETE FROM " stringByAppendingString:[self quickTableName]]; delsql = [delsql stringByAppendingString:@" WHERE c_name="]; @@ -561,7 +594,8 @@ static OCSStringFormatter *stringFormatter = nil; /* release channels and return */ [self releaseChannel:storeChannel]; - [self releaseChannel:quickChannel]; + if (!self->ofFlags.sameTableForQuick) + [self releaseChannel:quickChannel]; return error; } diff --git a/OGoContentStore/OCSFolderManager.h b/OGoContentStore/OCSFolderManager.h index 6ce48480..88a95c84 100644 --- a/OGoContentStore/OCSFolderManager.h +++ b/OGoContentStore/OCSFolderManager.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2004 SKYRIX Software AG + Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __OGoContentStore_OCSFolderManager_H__ #define __OGoContentStore_OCSFolderManager_H__ diff --git a/OGoContentStore/Version b/OGoContentStore/Version index 78e0144f..2c5bdd60 100644 --- a/OGoContentStore/Version +++ b/OGoContentStore/Version @@ -2,7 +2,7 @@ MAJOR_VERSION=0 MINOR_VERSION=9 -SUBMINOR_VERSION:=20 +SUBMINOR_VERSION:=21 # v0.9.19 requires libNGiCal v4.5.40 # v0.9.18 requires libNGiCal v4.5.38 -- 2.39.5