personalFolderInfoInserts_OBJC_FILES = pfinserts.m
-adaptorChannelInserts_OBJC_FILES = inserts.m
+adaptorChannelInserts_OBJC_FILES = inserts.m NSArray+random.m
adaptorChannelInserts_TOOL_LIBS += -lGDLAccess
--- /dev/null
+/*
+ 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_ */
--- /dev/null
+/*
+ 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
{
- hostName = "agenor-db";
+ hostName = "localhost";
userName = "agenor";
password = "";
databaseName = "SOGo1";
className = EOGenericRecord;
primaryKeyAttributes = ( pkey );
attributesUsedForLocking = ( pkey,
- dir,
- cn,
+ DIR,
+ CN,
mailto
);
classProperties = ( pkey,
- dir,
- cn,
+ DIR,
+ CN,
mailto
);
attributes = (
},
{
columnName = "c_dir";
- name = "dir";
+ name = "DIR";
valueClassName = "NSString";
externalType = "VARCHAR(255)";
allowsNull = N;
},
{
columnName = "c_cn";
- name = "cn";
+ name = "CN";
valueClassName = "NSString";
externalType = "VARCHAR(40)";
allowsNull = N;
#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);
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 {
}
}
}
- 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");
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
--- /dev/null
+// !$*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;
+}