|
|
1.1 ! root 1: /*-------------------------------------------------------------------------- ! 2: * ! 3: * You may freely copy, distribute, and reuse the code in this example. ! 4: * SHL Systemhouse disclaims any warranty of any kind, expressed or ! 5: * implied, as to its fitness for any particular use. ! 6: * ! 7: * ! 8: * AccessLevel ! 9: * ! 10: * Inherits From: NSObject ! 11: * ! 12: * Conforms To: None ! 13: * ! 14: * Declared In: AccessLevel.h ! 15: * ! 16: *------------------------------------------------------------------------*/ ! 17: #import "AccessLevel.h" ! 18: #import "ScrollViewExtensions.h" ! 19: #import <eoaccess/eoaccess.h> ! 20: #import <appkit/appkit.h> ! 21: ! 22: ! 23: ! 24: ! 25: @implementation AccessLevel ! 26: ! 27: - connect: sender ! 28: { ! 29: NSString *path; ! 30: ! 31: [messageConsole clear: nil]; ! 32: [messageConsole sprintf: "connecting to database...\n"]; ! 33: ! 34: [messageConsole sprintf: "obtaining model path...\n"]; ! 35: if ((path = [EOModel findPathForModelNamed: ! 36: [NSString stringWithCString:"Authors"]]) == nil) ! 37: { ! 38: NXRunAlertPanel (NULL, "Unable to obtain model path", ! 39: NULL, NULL, NULL); ! 40: [messageConsole sprintf: "unable to obtain model path\n"]; ! 41: return nil; ! 42: } ! 43: ! 44: [modelPath setStringValue: [path cString]]; ! 45: ! 46: [messageConsole sprintf: "initializing model...\n"]; ! 47: if ((model = [[EOModel alloc] initWithContentsOfFile:path]) == nil) ! 48: { ! 49: NXRunAlertPanel (NULL, "Unable to initialize model", NULL, NULL, NULL); ! 50: [messageConsole sprintf: "unable to initialize model\n"]; ! 51: return nil; ! 52: } ! 53: ! 54: [messageConsole sprintf: "creating adaptor...\n"]; ! 55: if ((adaptor = [EOAdaptor adaptorWithModel: model]) == nil) ! 56: { ! 57: NXRunAlertPanel (NULL, "Unable to create adaptor", NULL, NULL, NULL); ! 58: [messageConsole sprintf: "unable to create adaptor\n"]; ! 59: return nil; ! 60: } ! 61: ! 62: [messageConsole sprintf: "creating context...\n"]; ! 63: if ((context = [adaptor createAdaptorContext]) == nil) ! 64: { ! 65: NXRunAlertPanel (NULL, "Unable to create context", NULL, NULL, NULL); ! 66: [messageConsole sprintf: "unable to create context\n"]; ! 67: return nil; ! 68: } ! 69: ! 70: [messageConsole sprintf: "creating channel...\n"]; ! 71: if ((channel = [context createAdaptorChannel]) == nil) ! 72: { ! 73: NXRunAlertPanel (NULL, "Unable to create channel", NULL, NULL, NULL); ! 74: [messageConsole sprintf: "unable to create channel\n"]; ! 75: return nil; ! 76: } ! 77: ! 78: ! 79: // Bring up a login panel and get the valid connection dictionary ! 80: ! 81: if(![adaptor runLoginPanelAndValidateConnectionDictionary]) { ! 82: [messageConsole sprintf: "invalid login\n"]; ! 83: return nil; ! 84: } ! 85: else { ! 86: [adaptor setConnectionDictionary: [adaptor connectionDictionary]]; ! 87: [messageConsole sprintf: "opening channel...\n"]; ! 88: if ([channel openChannel] == NO) ! 89: { ! 90: NXRunAlertPanel (NULL, "Unable to open channel", ! 91: NULL, NULL, NULL); ! 92: [messageConsole sprintf: "unable to open channel\n"]; ! 93: return nil; ! 94: } ! 95: } ! 96: ! 97: [messageConsole sprintf:"channel %s open\n\n", ! 98: [channel isOpen] ? "is" : "is not"]; ! 99: [connectButton setEnabled: ! [channel isOpen]]; ! 100: [selectButton setEnabled: [channel isOpen]]; ! 101: return self; ! 102: } ! 103: ! 104: ! 105: - select: sender ! 106: { ! 107: int count = 0; ! 108: id entity, qualifier, attributes, dictionary; ! 109: ! 110: [resultConsole clear: nil]; ! 111: [messageConsole sprintf: "beginning transaction...\n"]; ! 112: ! 113: if ([context beginTransaction] == NO) ! 114: { ! 115: NXRunAlertPanel (NULL, "Unable to begin transaction", ! 116: NULL, NULL, NULL); ! 117: [messageConsole sprintf: "unable to begin transaction\n"]; ! 118: return nil; ! 119: } ! 120: ! 121: [messageConsole sprintf: "obtaining entity...\n"]; ! 122: if ((entity = [model entityNamed: @"authors"]) == nil) ! 123: { ! 124: NXRunAlertPanel (NULL, "Unable to obtain entity authors", ! 125: NULL, NULL, NULL); ! 126: [messageConsole sprintf: "unable to obtain entity authors\n"]; ! 127: return nil; ! 128: } ! 129: ! 130: [messageConsole sprintf: "obtaining qualifier...\n"]; ! 131: if ((qualifier = [entity qualifier]) == nil) ! 132: { ! 133: NXRunAlertPanel (NULL, "Unable to obtain qualifier", ! 134: NULL, NULL, NULL); ! 135: [messageConsole sprintf: "unable to obtain qualifier\n"]; ! 136: return nil; ! 137: } ! 138: ! 139: [messageConsole sprintf: "obtaining attributes...\n"]; ! 140: if ((attributes = [entity attributes]) == nil) ! 141: { ! 142: NXRunAlertPanel (NULL, "Unable to obtain attributes", ! 143: NULL, NULL, NULL); ! 144: [messageConsole sprintf: "unable to obtain attributes\n"]; ! 145: return nil; ! 146: } ! 147: ! 148: [messageConsole sprintf: "selecting attributes...\n"]; ! 149: if ([channel selectAttributes:attributes ! 150: describedByQualifier: qualifier fetchOrder:nil lock:NO] == NO) ! 151: { ! 152: NXRunAlertPanel (NULL, "Unable to select attributes", ! 153: NULL, NULL, NULL); ! 154: [messageConsole sprintf: "unable to select attributes\n"]; ! 155: return nil; ! 156: } ! 157: ! 158: while ((dictionary = [channel fetchAttributes:attributes ! 159: withZone:[(EOAdaptor*)adaptor zone]]) != nil) ! 160: { ! 161: [resultConsole sprintf: "%s\n", ! 162: [[(NSString*)dictionary description] cString]]; ! 163: count++; ! 164: } ! 165: ! 166: [messageConsole sprintf: "\n%d records found\n\n", count]; ! 167: ! 168: [messageConsole sprintf: "rolling back transaction...\n"]; ! 169: if ([context rollbackTransaction] == NO) ! 170: { ! 171: NXRunAlertPanel (NULL, "Unable to rollback transaction", ! 172: NULL, NULL, NULL); ! 173: [messageConsole sprintf: "unable to rollback transaction\n"]; ! 174: return nil; ! 175: } ! 176: ! 177: [messageConsole sprintf: "done\n\n"]; ! 178: return self; ! 179: } ! 180: ! 181: ! 182: @end ! 183:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.