]> err.no Git - scalable-opengroupware.org/commitdiff
my first EOAdaptorChannel access! :)
authorznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 21 May 2004 18:31:03 +0000 (18:31 +0000)
committerznek <znek@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 21 May 2004 18:31:03 +0000 (18:31 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@5 d1b88da0-ebda-0310-925b-ed51d893ca5b

db/tests/znek/GNUmakefile
db/tests/znek/NSArray+random.h [new file with mode: 0644]
db/tests/znek/NSArray+random.m [new file with mode: 0644]
db/tests/znek/connection.plist
db/tests/znek/inserts.eomodel
db/tests/znek/inserts.m
db/tests/znek/tests.xcode/project.pbxproj [new file with mode: 0644]

index f73eab261cda1b247b8992c37e56edeea3f9544e..c3c66bb054a89cd42939389a5866a81a0c0c68bb 100644 (file)
@@ -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 (file)
index 0000000..bd83421
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2004 Marcus Mueller <znek@mulle-kybernetik.com>
+
+ 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 <Foundation/Foundation.h>
+
+
+@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 (file)
index 0000000..26d6d2e
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2004 Marcus Mueller <znek@mulle-kybernetik.com>
+
+ 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 <stdlib.h>
+
+
+@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
index 0e6cda4f7e4f69e577a9cb22d097e67bbd1c8ab0..51b7d87e1fc8d2ff0466a358b3e459110d9c5a05 100644 (file)
@@ -1,5 +1,5 @@
 {
-  hostName     = "agenor-db";
+  hostName     = "localhost";
   userName     = "agenor";
   password     = "";
   databaseName = "SOGo1";
index c801cfd01bc6dd4212b69e576d4e6616a679aa97..745d64434dcbc7d2ef2e9247ed2996335f18c461 100644 (file)
         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;
index 87bb6ff6f9b5b01794a949f319a48789f80d3e5b..f639e65f9e3d73013325833ca763b3ed8bac5c61 100644 (file)
@@ -6,27 +6,31 @@
 #import <Foundation/Foundation.h>
 #import <EOAccess/EOAccess.h>
 #import <NGExtensions/NGExtensions.h>
+#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 (file)
index 0000000..857cb6d
--- /dev/null
@@ -0,0 +1,175 @@
+// !$*UTF8*$!
+{
+       archiveVersion = 1;
+       classes = {
+       };
+       objectVersion = 39;
+       objects = {
+               AD3BDFED065E3F7100D1D0A5 = {
+                       children = (
+                               AD3BDFFE065E3FBB00D1D0A5,
+                               AD3BE001065E3FC100D1D0A5,
+                       );
+                       isa = PBXGroup;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               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 = "<group>";
+               };
+               AD3BDFF8065E3FB500D1D0A5 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = text;
+                       path = GNUmakefile.preamble;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BDFF9065E3FB500D1D0A5 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = lmail.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BDFFA065E3FB500D1D0A5 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = lpe.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BDFFB065E3FB500D1D0A5 = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = pfinserts.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BDFFE065E3FBB00D1D0A5 = {
+                       children = (
+                               AD3BDFF7065E3FB500D1D0A5,
+                               AD3BDFF8065E3FB500D1D0A5,
+                       );
+                       isa = PBXGroup;
+                       name = Makefiles;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BE001065E3FC100D1D0A5 = {
+                       children = (
+                               AD3BDFF9065E3FB500D1D0A5,
+                               AD3BDFFA065E3FB500D1D0A5,
+                               AD3BDFFB065E3FB500D1D0A5,
+                               AD3BE020065E413D00D1D0A5,
+                       );
+                       isa = PBXGroup;
+                       name = Source;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BE006065E3FF500D1D0A5 = {
+                       explicitFileType = sourcecode.c.objc;
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       path = inserts.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BE020065E413D00D1D0A5 = {
+                       children = (
+                               ADFFCCE8065E6B24003E487A,
+                               AD3BE022065E41B300D1D0A5,
+                               AD3BE006065E3FF500D1D0A5,
+                               AD3BE021065E416500D1D0A5,
+                       );
+                       isa = PBXGroup;
+                       name = adaptorInserts;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BE021065E416500D1D0A5 = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = text;
+                       path = inserts.eomodel;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD3BE022065E41B300D1D0A5 = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = text.plist;
+                       path = connection.plist;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               ADFFCCDA065E6B1C003E487A = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = "NSArray+random.h";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               ADFFCCDB065E6B1C003E487A = {
+                       fileEncoding = 4;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = "NSArray+random.m";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               ADFFCCE8065E6B24003E487A = {
+                       children = (
+                               ADFFCCDA065E6B1C003E487A,
+                               ADFFCCDB065E6B1C003E487A,
+                       );
+                       isa = PBXGroup;
+                       name = Extensions;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+       };
+       rootObject = AD3BDFF1065E3F7100D1D0A5;
+}