From: znek Date: Fri, 21 May 2004 18:31:03 +0000 (+0000) Subject: my first EOAdaptorChannel access! :) X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06c121baad816a67463ab02db103f80da9da92a7;p=scalable-opengroupware.org my first EOAdaptorChannel access! :) git-svn-id: http://svn.opengroupware.org/SOGo/trunk@5 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/db/tests/znek/GNUmakefile b/db/tests/znek/GNUmakefile index f73eab26..c3c66bb0 100644 --- a/db/tests/znek/GNUmakefile +++ b/db/tests/znek/GNUmakefile @@ -15,7 +15,7 @@ findLongestEMailAddress_OBJC_FILES = lmail.m personalFolderInfoInserts_OBJC_FILES = pfinserts.m -adaptorChannelInserts_OBJC_FILES = inserts.m +adaptorChannelInserts_OBJC_FILES = inserts.m NSArray+random.m adaptorChannelInserts_TOOL_LIBS += -lGDLAccess diff --git a/db/tests/znek/NSArray+random.h b/db/tests/znek/NSArray+random.h new file mode 100644 index 00000000..bd834217 --- /dev/null +++ b/db/tests/znek/NSArray+random.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2004 Marcus Mueller + + This file is part of OGo + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. + */ +// $Id$ +// Created by znek on Fri May 21 2004. + +#ifndef __NSArray_random_H_ +#define __NSArray_random_H_ + +#import + + +@interface NSArray (RandomExt) +- (id)randomObject; +@end + +#endif /* __NSArray_random_H_ */ diff --git a/db/tests/znek/NSArray+random.m b/db/tests/znek/NSArray+random.m new file mode 100644 index 00000000..26d6d2ea --- /dev/null +++ b/db/tests/znek/NSArray+random.m @@ -0,0 +1,42 @@ +/* + Copyright (C) 2004 Marcus Mueller + + This file is part of OGo + + OGo is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + OGo 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 Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with OGo; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. + */ +// $Id$ +// Created by znek on Fri May 21 2004. + + +#import "NSArray+random.h" +#include + + +@implementation NSArray (RandomExt) + +- (id)randomObject { + unsigned i, count; + + count = [self count]; + if(count == 0) + return nil; + + i = (unsigned)random() % count; + return [self objectAtIndex:i]; +} + +@end diff --git a/db/tests/znek/connection.plist b/db/tests/znek/connection.plist index 0e6cda4f..51b7d87e 100644 --- a/db/tests/znek/connection.plist +++ b/db/tests/znek/connection.plist @@ -1,5 +1,5 @@ { - hostName = "agenor-db"; + hostName = "localhost"; userName = "agenor"; password = ""; databaseName = "SOGo1"; diff --git a/db/tests/znek/inserts.eomodel b/db/tests/znek/inserts.eomodel index c801cfd0..745d6443 100644 --- a/db/tests/znek/inserts.eomodel +++ b/db/tests/znek/inserts.eomodel @@ -19,13 +19,13 @@ className = EOGenericRecord; primaryKeyAttributes = ( pkey ); attributesUsedForLocking = ( pkey, - dir, - cn, + DIR, + CN, mailto ); classProperties = ( pkey, - dir, - cn, + DIR, + CN, mailto ); attributes = ( @@ -38,7 +38,7 @@ }, { columnName = "c_dir"; - name = "dir"; + name = "DIR"; valueClassName = "NSString"; externalType = "VARCHAR(255)"; allowsNull = N; @@ -46,7 +46,7 @@ }, { columnName = "c_cn"; - name = "cn"; + name = "CN"; valueClassName = "NSString"; externalType = "VARCHAR(40)"; allowsNull = N; diff --git a/db/tests/znek/inserts.m b/db/tests/znek/inserts.m index 87bb6ff6..f639e65f 100644 --- a/db/tests/znek/inserts.m +++ b/db/tests/znek/inserts.m @@ -6,27 +6,31 @@ #import #import #import +#import "NSArray+random.h" #define DEBUG 0 -#define ALL_RECORDS @"/home/znek/all-BALI.plist" +#define PERSON_RECORDS @"/home/znek/all-BALI.plist" int main(int argc, char **argv, char **env) { NSAutoreleasePool *pool; - EOModel *m = nil; - EOAdaptor *a; - EOAdaptorContext *ctx; - EOAdaptorChannel *ch; - NSDictionary *conDict; - + EOModel *m = nil; + EOAdaptor *a; + EOAdaptorContext *ctx; + EOAdaptorChannel *ch; + NSDictionary *conDict; + NSUserDefaults *ud; + pool = [[NSAutoreleasePool alloc] init]; #if LIB_FOUNDATION_LIBRARY [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; #endif + ud = [NSUserDefaults standardUserDefaults]; + conDict = [NSDictionary dictionaryWithContentsOfFile:@"connection.plist"]; NSLog(@"condict is %@", conDict); @@ -60,25 +64,18 @@ int main(int argc, char **argv, char **env) { if ([ctx beginTransaction]) { NSLog(@"began tx .."); #endif - /* do something */ { - NSAutoreleasePool *lpool = [[NSAutoreleasePool alloc] init]; - EOEntity *e; EOSQLQualifier *q; NSArray *attrs; NSString *expr; -#if 0 +#if 1 NS_DURING if([ctx beginTransaction]) { expr = @"DROP TABLE SOGo_test"; if([ch evaluateExpression:expr]) { - attrs = [ch describeResults]; - NSLog(@"results: %@", attrs); - - if([ctx commitTransaction]) { NSLog(@"DROP'ed table - committed."); } else { @@ -86,18 +83,19 @@ int main(int argc, char **argv, char **env) { } } } - NS_HANDLER + NS_HANDLER + NSLog(@"DROP table aborted - %@", [localException reason]); - NSLog(@"a"); - - NS_ENDHANDLER + [ctx rollbackTransaction]; + + NS_ENDHANDLER #endif - + NS_DURING if([ctx beginTransaction]) { - expr = @"CREATE TABLE SOGo_test (c_id INT PRIMARY KEY, c_dir VARCHAR(255) NOT NULL, c_cn VARCHAR(40) NOT NULL, c_mailto VARCHAR(120) NOT NULL);"; + expr = @"CREATE TABLE SOGo_test (c_id INT PRIMARY KEY, c_dir VARCHAR(255) NOT NULL, c_cn VARCHAR(40) NOT NULL, c_mailto VARCHAR(120) NOT NULL);"; if([ch evaluateExpression:expr]) { if([ctx commitTransaction]) { NSLog(@"CREATE TABLE - committed"); @@ -114,7 +112,54 @@ int main(int argc, char **argv, char **env) { NS_ENDHANDLER; - [lpool release]; + // Now for some serious business... + if([ctx beginTransaction]) { + NSString *path; + NSArray *allPersonRecords; + unsigned i, count; + EOEntity *e; + NSArray *attributes, *attributesNames; + + path = [ud stringForKey:@"PersonRecords"]; + if(path == nil) + path = PERSON_RECORDS; + + allPersonRecords = [NSArray arrayWithContentsOfFile:path]; + NSCAssert([allPersonRecords count] != 0, @"allPersonRecords empty?!"); + + e = [m entityNamed:@"Test"]; + attributes = [e attributesUsedForInsert]; + attributesNames = [e attributesNamesUsedForInsert]; + + for(i = 0; i < 10; i++) { + NSDictionary *pdata, *values; + NSMutableDictionary *row; + NSAutoreleasePool *lpool = [[NSAutoreleasePool alloc] init]; + NSNumber *newPK; + + pdata = [allPersonRecords randomObject]; + NSLog(@"pdata: %@", pdata); + + newPK = [NSNumber numberWithUnsignedInt:i + 1]; + row = [pdata mutableCopy]; + [row setObject:newPK forKey:[[e primaryKeyAttributeNames] lastObject]]; + values = [e convertValuesToModel:row]; +#if 0 + pkey = [e primaryKeyForRow:values]; + NSLog(@"pkey: %@", pkey); +#endif + if (![ch insertRow:values forEntity:e]) + NSLog(@"Couldn't insert row!"); + [lpool release]; + } + if([ctx commitTransaction]) { + NSLog(@"INSERTS - committed"); + } else { + NSLog(@"couldn't commit INSERTS!"); + } + } else { + NSLog(@"Couldn't begin transaction?"); + } } #if 0 diff --git a/db/tests/znek/tests.xcode/project.pbxproj b/db/tests/znek/tests.xcode/project.pbxproj new file mode 100644 index 00000000..857cb6d5 --- /dev/null +++ b/db/tests/znek/tests.xcode/project.pbxproj @@ -0,0 +1,175 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 39; + objects = { + AD3BDFED065E3F7100D1D0A5 = { + children = ( + AD3BDFFE065E3FBB00D1D0A5, + AD3BE001065E3FC100D1D0A5, + ); + isa = PBXGroup; + refType = 4; + sourceTree = ""; + }; + AD3BDFEF065E3F7100D1D0A5 = { + buildRules = ( + ); + buildSettings = { + COPY_PHASE_STRIP = NO; + }; + isa = PBXBuildStyle; + name = Development; + }; + AD3BDFF0065E3F7100D1D0A5 = { + buildRules = ( + ); + buildSettings = { + COPY_PHASE_STRIP = YES; + }; + isa = PBXBuildStyle; + name = Deployment; + }; + AD3BDFF1065E3F7100D1D0A5 = { + buildSettings = { + }; + buildStyles = ( + AD3BDFEF065E3F7100D1D0A5, + AD3BDFF0065E3F7100D1D0A5, + ); + hasScannedForEncodings = 1; + isa = PBXProject; + mainGroup = AD3BDFED065E3F7100D1D0A5; + projectDirPath = ""; + targets = ( + ); + }; + AD3BDFF7065E3FB500D1D0A5 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = text; + path = GNUmakefile; + refType = 4; + sourceTree = ""; + }; + AD3BDFF8065E3FB500D1D0A5 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = text; + path = GNUmakefile.preamble; + refType = 4; + sourceTree = ""; + }; + AD3BDFF9065E3FB500D1D0A5 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = lmail.m; + refType = 4; + sourceTree = ""; + }; + AD3BDFFA065E3FB500D1D0A5 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = lpe.m; + refType = 4; + sourceTree = ""; + }; + AD3BDFFB065E3FB500D1D0A5 = { + fileEncoding = 30; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = pfinserts.m; + refType = 4; + sourceTree = ""; + }; + AD3BDFFE065E3FBB00D1D0A5 = { + children = ( + AD3BDFF7065E3FB500D1D0A5, + AD3BDFF8065E3FB500D1D0A5, + ); + isa = PBXGroup; + name = Makefiles; + refType = 4; + sourceTree = ""; + }; + AD3BE001065E3FC100D1D0A5 = { + children = ( + AD3BDFF9065E3FB500D1D0A5, + AD3BDFFA065E3FB500D1D0A5, + AD3BDFFB065E3FB500D1D0A5, + AD3BE020065E413D00D1D0A5, + ); + isa = PBXGroup; + name = Source; + refType = 4; + sourceTree = ""; + }; + AD3BE006065E3FF500D1D0A5 = { + explicitFileType = sourcecode.c.objc; + fileEncoding = 4; + isa = PBXFileReference; + path = inserts.m; + refType = 4; + sourceTree = ""; + }; + AD3BE020065E413D00D1D0A5 = { + children = ( + ADFFCCE8065E6B24003E487A, + AD3BE022065E41B300D1D0A5, + AD3BE006065E3FF500D1D0A5, + AD3BE021065E416500D1D0A5, + ); + isa = PBXGroup; + name = adaptorInserts; + refType = 4; + sourceTree = ""; + }; + AD3BE021065E416500D1D0A5 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = text; + path = inserts.eomodel; + refType = 4; + sourceTree = ""; + }; + AD3BE022065E41B300D1D0A5 = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = text.plist; + path = connection.plist; + refType = 4; + sourceTree = ""; + }; + ADFFCCDA065E6B1C003E487A = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.h; + path = "NSArray+random.h"; + refType = 4; + sourceTree = ""; + }; + ADFFCCDB065E6B1C003E487A = { + fileEncoding = 4; + isa = PBXFileReference; + lastKnownFileType = sourcecode.c.objc; + path = "NSArray+random.m"; + refType = 4; + sourceTree = ""; + }; + ADFFCCE8065E6B24003E487A = { + children = ( + ADFFCCDA065E6B1C003E487A, + ADFFCCDB065E6B1C003E487A, + ); + isa = PBXGroup; + name = Extensions; + refType = 4; + sourceTree = ""; + }; + }; + rootObject = AD3BDFF1065E3F7100D1D0A5; +}