File: GDL2Intro.texi

package info (click to toggle)
gnustep-dl2 0.12.0-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,076 kB
  • sloc: objc: 61,761; makefile: 33
file content (901 lines) | stat: -rw-r--r-- 29,812 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
\input texinfo   @c -*-texinfo-*-
@c %**start of header
@setfilename GDL2Intro.info
@settitle GNUstep Database Library Introduction 0.1
@c %**end of header

@copying
@copyright{2006 Free Software Foundation}

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided also that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
@end copying

@raisesections

@dircategory Software libraries
@direntry
* GDL2: (GDL2Intro).   GNUstep Database Library Introduction.
@end direntry

@titlepage
@title GNUstep Database Library Introduction 
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
     
@c Output the table of the contents at the beginning.
@contents
     
@ifnottex
@node Top, Concepts, ,
@top GNUstep Database Library
@insertcopying
@end ifnottex

@chapter Introduction
This document is intended to get people started developing with GDL2.
A knowledge of objective-c and relational database concepts is assumed.

While not intended as a thorough reference or a replacement for the API docs
and surely omits details for the sake of simplicity it attempts to
provide a starting point for people unfamiliar with GDL2 or EOF
to get started developing their first application.

If you are reading this document from the GDL2 Sources, most example sources 
are provided in the ../../Examples/ directory.

@menu
* Concepts:: Important concepts 
* Classes:: A basic overview of important classes to know and understand.
* Model creation:: Describes different ways to create model files. 
* Project creation:: Creating a GDL2 project.
* Database creation:: Creating the database on the database server.
* Database connection:: Connecting to a database through an adaptor.
* Working with data:: Creating, Fetching, and updating data in the database. 
* EOInterface:: Developing graphical applications with EOInterface.
* Index:: Complete index.
@end menu


@node Concepts, Classes, Top, Top
@chapter Concepts 
@menu
* Key Value Coding:: Key Value Coding
@end menu

@node Key Value Coding, , ,Concepts
@chapter Key Value Coding
@cindex KVC, Key Value Coding
Key Value Coding is a concept used widely throughout GDL2,
it provides a mechanism by where you can access and modify an objects 
set/accessor methods or even instance variables directly, through a named key.

Additionally some classes may implement KVC in a way specific to the class.

@section Setting values through KVC
Setting values through key value coding will try to call a method
'-setKeyName:' with the value as the parameter to -setKeyName:
as a parameter failing that, if anObject had an instance variable
with the same name as the key that would be modified directly.

If anObject does not respond to `-setKeyName:` and there is no 
instance variable with the same name as the key, an exception is thrown.


@example
@verbatim
[anObject setValue:@"bar" forKey:@"foo"];
@end verbatim
@end example

Will first try to call -setFoo: then attempt to set the instance variable
named "foo" to "bar".

@section Accessing values through KVC

Accessing values through Key Value Coding first attempts to 
call the -keyName method on anObject if it responds.
If the object does not respond then it will try to access an instance
variable with the name of the key. 

If there is no method or instance variable with the name of the key an
exception will be thrown.

For example,
@example
@verbatim
[anObject valueForKey:@"foo"];
@end verbatim
@end example

Will first try to call -foo, then attempt to return instance variable named foo.

@section Key Paths
Key paths are a list of keys separated by a dot.

The first key accesses the key on the target object through normal KVC,
and each subsequent key is sent to the object returned through the previous
key in the list.

For example,
@example
@verbatim
[anObject valueForKeyPath:@"foo.bar"];
@end verbatim
@end example

Will be equivalent to
@example
@verbatim
[[anObject valueForKey:@"foo"] valueForKey:@"bar"];
@end verbatim
@end example

@section Type promotion
When a accessing a key, you may access keys for things such as standard c numerical
types, and they will be automatically promoted to their object equivalent

For example:
@example
@verbatim
[@"foo" valueForKey:@"length"];
@end verbatim
@end example
Returns a NSNumber object containing '3'.


@section Class specific implementation
By implementing valueForKey: and setValueForKey: classes can implement
functionality to contain keys in an instance variable such as a dictionary,
but they can also implement something to work on a collection of objects.

For instance NSArray implements KVC to forward key value coding to all objects
in the array.

Suppose we have an array contain a few string objects.
@example
("Example", "array", "containing", "strings")
@end example

If we get the value for the key length, it will return an NSArray of NSNumbers
@example 
(7, 5, 10, 7).
@end example

@node Classes, Model creation, Concepts, Top
@chapter Classes

@section Model classes
The model related classes are important in that they define a databases
structure.  Giving GDL2 a way to map a relational database into a set of 
objects.

@menu
* EOModel class:: EOModel    
* EOEntity class:: EOEntity
* EOAttribute class:: EOAttribute
* EORelationship class:: EORelationship
* EOModelGroup class:: EOModelGroup
@end menu

@section Database specific classes
The database specific classes loadable through bundles provide a method
for GDL2 to connect to and abstract implementation details between
different database implementations.

Currently adaptors for SQLite3 and PostgreSQL exist.
@menu
* EOAdaptor class:: EOAdaptor
* EOAdaptorChannel class:: EOAdaptorChannel
* EOAdaptorContext class:: EOAdaptorContext
@end menu

@section Data oriented classes
The data oriented classes relate to actual data manipulation and management.
@menu
* EODataSource class:: EODataSource
* EOEditingContext class:: EOEditingContext
* EOGenericRecord class:: EOGenericRecord
@end menu 

@node EOModel class, EOEntity class, , Classes
@section EOModel class
@cindex class, EOModel

@subsection overview
A model represents GDL2s interface to a database.  It contains
information required to connect to the database along with entities
and stored procedures.

All the model classes can be written to and read from property list files
in the form of .eomodel or .eomodeld files. While .eomodel files contain a 
model and all its entities and objects in a single property list, .eomodeld files
are a directory with each of the property lists in their own file.

Typically you won't create an model through manual instantiation of the classes
but store them in and read them from a property list. We have provided an
example .eomodel file @xref{Example model file}.

@noindent
An EOModel Typically has:
@enumerate
@item
A Name
@item
An adaptor name
@item
A connection dictionary
@item
An array of entities
@end enumerate

@node EOEntity class, EOAttribute class, EOModel class, Classes 
@section EOEntity class
@cindex class, EOEntity

@subsection overview
An entity contains information pertaining to a table in a database
in the form of attributes and relationships.

@noindent
Additionally an entity contains:
@enumerate
@item
An array of class properties
@item
An array of primary key attributes
@item
A class name
@item
An External name
@end enumerate

@subsection Class properties
A class property of an entity can be either an attribute or a relationship.
typically class properties are the set of attributes or relationships 
which are user visible and need to be set or accessed by the user.
Primary and Foreign keys attributes are usually derived from other
attributes or generated automatically and so they are not typically
class properties.

A class property will be available through Key Value Coding for access
and modification, in an instance of an Enterprise object.

@subsection Class name
an EOEntity's class name represents the name of the class which will be
instantiated when creating an Enterprise Object such as EOGenericRecord
or a custom object.

@subsection Primary Key Attributes
Primary key attributes specify which attributes uniquely identify a row
in the table, they are typically generated automatically by GDL2.
They correspond directly to the relational database concept.

@subsection External name
The external name represents the table name in the database server,
and in any SQL the adaptor might generate.

@node EOAttribute class, EORelationship class, EOEntity class, Classes 
@section EOAttribute class
@cindex class, EOAttribute

@subsection overview
An attribute typically maps a table column to an instance variable, 
in which case the attribute is a class property.  Some attributes 
represent foreign keys which are used to create realationships yet do 
not correspond to a property in the enterprise object.  Other attributes 
may represent primary keys which needn't be class property either.  In fact 
some parts of framework work more smoothly if primary key attributes and 
foreign key attributes are not class properties.

@noindent
Attributes typically contain:
@enumerate
@item
A name
@item
A column name
@item
An adaptor value type
@item
An external type
@item
A value type
@item
A value class name
@item
A value factory method name
@item
a factory method argument type
@end enumerate

@noindent
Some additional properties an attribute may have:
@enumerate
@item
Read only
@item
Allows null
@item
Width
@item
Precision
@item
Scale
@end enumerate

@subsection Name
The attributes name when the attribute is a class property is used
as the key when doing key value coding on an enterprise object.

It also uniquely identifies the attribute in its entity
there many not be an attribute with the same name as another attribute or 
relationship in an entity.

@subsection Column name
The adaptor uses the column name in generating SQL.

@subsection Adaptor value type
Indicates the type of the attribute as contained in the database

@noindent
Valid adaptor value types are:
@enumerate
@item
EOAdaptorNumberType
@item
EOAdaptorCharactersType
@item
EOAdaptorBytesType
@item
EOAdaptorDateType
@end enumerate

Corresponding to numerical, string, raw data, and date value types.

@subsection External type
An external type is a string representing an adaptor specific database type
different adaptors may use different names
where the PostgreSQL adaptor might use 'char'.
The SQLite3 Adaptor might use 'TEXT'

it gives you full control on how the data is stored in the specific adaptor
where the adaptor value type allows you to specify a few generic values. 

@subsection Value type
Value types are a string with a single character such as 'f' for floats
'c' for chars a full list of the standard types is available in the 
GDL2 API reference for EOAttributes -valueType method.

The value type allows you to further refine the adaptor value type
where EOAdaptorNumberType might represent a integer, float, or double type.

@subsection Value class name
The value class name specifies the class which will be present in an
Enterprise Object containing the attribute.

A property of this class will be instantiated when a field is retrieved from
the database, similarly a instance of this will be converted into the
external type when being sent to the datbase server.

@subsection Value factory method name
When the Value Class Name is a custom object for instance NSImage
created from a blob of data. The value factory method name denotes
the initializer for the class, used to create a new instance of the custom
class.

The value class name is an NSString representing a selector accepting a single
argument suitable for passing to the NSSelectorFromString function.

@subsection Value factory argument type
This is the type of the argument sent to the value factory method name.

@noindent
Valid types are
@enumerate
@item
EOFactoryMethodArgumentIsNSData
@item
EOFactoryMethodArgumentIsNSString
@item
EOFactoryMethodArgumentIsBytes
@end enumerate



@node EORelationship class, EOModelGroup class, EOAttribute class, Classes 
@section EORelationship class
@cindex class, EORelationship

@subsection overview
A relationship represents a connecton between entities and are described 
with EOJoin's.  A join defines source and destination attributes --  The
attributes of the joining entity which must match.

A relationship may be of type to-one or to-many.  In a to-many the 
destination will be an array of objects, and a to-one relationships 
destination a single object.

Typically a relationship is a class property.  Yet some relationships may 
soley be used for flattening other relationships which are class properties, 
yet need not be class properties themselves.

@node EOModelGroup class, EOAdaptor class, EORelationship class, Classes 
@section EOModelGroup class
@cindex class, EOModelGroup

@subsection overview
When models have relationships to other models, they ask their model group.

There is a special model group - the default model group - which contains 
all the models in the applications resources and the resources of any 
frameworks the application uses.  If your model file is not available through
application or framework resources you will need to add it to a model group.

@node EOAdaptor class, EOAdaptorContext class, EOModelGroup class, Classes 
@section EOAdaptor class
@cindex class, EOAdaptor

@subsection overview
An adaptor abstracts the difference between different database
implementations.  It can connect to the database with the help of a
connection dictionary and create and execute SQL statements.

While an adaptor is made up of many different classes. The EOAdaptor class is sort of an entry point into the different available classes.

And a typical use for the EOAdaptor class is creating an instance of a
specific adaptor, either by name or through the adaptor name in a model.

Typical methods for the EOAdaptor class are:
@enumerate
@item
-createAdaptorContext
@item
-runLoginPanel
@item
-assertConnectionDictionaryIsValid
@item
+adaptorWithModel:
@end enumerate

@node EOAdaptorContext class, EOAdaptorChannel class, EOAdaptor class, Classes
@section EOAdaptorContext class
An EOAdaptorContext can create an adaptor channel and will transparently handle
transactions for the channel, It can begin, commit, roll back transactions.

Additionaly you can enable debugging on the context and its channels.

Typical methods for an EOAdaptorContext:
@enumerate
@item
-createAdaptorChannel
@item
-setDebugEnabled:
@end enumerate

@node EOAdaptorChannel class, EODataSource class, EOAdaptorContext class, Classes
@section EOAdaptorChannel class

An adaptor channel can open and close a connection to the adaptors database server. Along with fetch rows from the database and create, update, and delete rows in the database.

It is the main communication channel for gdl2, in creating the connection to the database, and executing any SQL statements which have been prepared through
EOSQLExpression.  Though it also has methods for building SQL expressions from entities, and possibly turning the results back into enterprise objects.

Because EOAdaptorChannel can create most SQL statements for you,
you'll rarely need to do that yourself, though it is available if needed.

Typical methods for an EOAdaptorChannel:
@enumerate
@item
-openChannel
@item
-closeChannel
@item
-isOpen
@end enumerate


@node EODataSource class, EOEditingContext class, EOAdaptorChannel class, Classes
@section EODataSource class
@cindex class, EODataSource

@subsection overview
EODataSource is an abstract base class, and implements no real functionality on its own,
instead you'll access EODataSource subclass.

A data source represents a collection of rows inside of a table. 
It can create rows, delete and provide access to the individual rows 
represented as Enterprise objects.

@noindent
Typical methods for an EODataSource subclass:
@enumerate
@item
-fetchObjects
@item
-createObject:
@item
-deleteObject:
@item
-insertObject:
@item
-dataSourceQualifiedByKey:
@end enumerate 

@subsection Fetch objects
The -fetchObjects method will return an array of enterprise objects.
Typically these will be retrieved directly from data in the database server.
Then the caller will save the array for access or modification.

@subsection Creating objects
The -createObject: method will create a new enterprise object for insertion into the database.
A subclass will generally insert this new object into an editing context.
Though the caller is responsible for inserting the object into the data source with -insertObject:.

@subsection Inserting objects
The -insertObject: method will schedule the object for addition into the database server
EditingContexts changes are saved to the database.

@subsection Deleting objects
The -deleteObject: method will schedule the object for removal from the database server
when the EOEditingContexts changes are saved to the database.

@subsection Qualified DataSources
Subclasses may implement this method to return a detail data source.

A detail data source is a datasource which is created from following a relationship 
in an object of the receiever: the master object.

in our example you might have a data source for the authors entity
and qualify a detail data source, with the toBooks key. 

@subsection EODatabaseDataSource class
EODatabaseDataSource class is a subclass of EODataSource.

To initialize an EODatabaseDataSource you'll give it a reference to an EOEditingContext
and an entity name.

EODatabaseDataSource initializers:
@enumerate
@item
-initWithEditingContext:entityName:
@item
-initWithEditingContext:entityName:fetchSpecificationName:
@end enumerate

Once initialized, you can call the EODataSource methods on it, to
create fetch insert, and delete objects from the datasource.

@node EOEditingContext class, EOGenericRecord class, EODataSource class, Classes
@section EOEditingContext class
@cindex class, EOEditingContext

@subsection overview
An editing context is responsible for managing changes to enterprise objects
and provides the ability to save and undo those changes. Including inserts, updates, and deletes.

Typical methods of the EOEditingContext class:
@enumerate
@item
-saveChanges:
@item
-revert:
@item
-undo:
@item
-redo:
@item
-insertObject:
@item
-deleteObject:
@end enumerate

You may have noticed that there is no mention of a method for modifying an object through an EOEditingContext. As you will modify the objects directly, and EOEditingContext will merely take note of the changes, and save snapshots of the objects as they are being modified so you can undo those changes.

@node EOGenericRecord class, , EOEditingContext class, Classes
@section EOGenericRecord class
@cindex class, EOGenericRecord 

@subsection overview
EOGeneric record represents an actual row in a table being the default 
enterprise object it contains no custom business logic and is accessible solely
through key value coding.

Where an entity represents the description of the table. It's columns and types.
enterprise objects represent the data contained in the table.

EOGenericRecords are generally created with a reference to an entity.
They export as keys the class properties of the entity, for access and modification.

If you have an EOGenericRecord from the 'authors' entity
of our example model you could set the authors name as so.
@xref{Example model file}.

@example
@verbatim
[anAuthor takeValue:@"Anonymous" forKey:@"name"];
@end verbatim
@end example

And retrieve the author name with:
@example
@verbatim
[anAuthor valueForKey:@"name"];
@end verbatim
@end example

@node Model creation, Project creation, Classes, Top
@chapter Model Creation 
@cindex model creation 
Models can be created in 3 ways 

@enumerate
@item
Manual written with property lists.
@item
Hard coding the model in objective-c.
@item
Creation of plists with the DBModeler application.
@end enumerate

while DBModeler provides the easiest way, followed by manually writing the
property lists, and hard coding the model is both tedious and complicated.

@menu
* Example model file:: An example property list for a .eomodel file.
* Creating with DBModeler:: Instructions for recreating the property list with
DBModeler
@end menu


@node Example model file, Creating with DBModeler, Model creation, Model creation  
@subsection Example model file
Below is a example property list model created with DBModeler,
it contains a Model for a library 2 entities, author and book

author contains 2 attributes, authorID the primary key number, and name a string
book contains 3 attributes, bookID the primary key number, authorID a
foreign key number, and title a string.

author and book each contain a relationship
author a to-many relationship to each of the authors books,
and book a to-one relationship to the books author 
for the sake of demonstration i'm ignoring books with multiple authors.

it also contains an adaptor name, and an adaptor specific connection dictionary.

@verbatiminclude ../../Examples/library.eomodel

@node Creating with DBModeler, , Example model file, Model creation 
@subsection Creating with DBModeler
To recreate the example model with DBModeler,

select Document, New from the main menu then property Add entity twice.
set the name and external names to 'authors' and 'books'

select Document, Set Adaptor Info, and select SQLite, and click Ok,
this will bring up the SQLite login panel, where you need to provide it a path
for where to create the model file. 

Each Adaptor will have different requirements, so each login panel is quite
different. Other adaptors may have a server address, username, and database names.

select the authors entity in the outline view, after expanding the model
add an attribute to authors by selecting Property, Add attribute
set the name and column name to 'authorID', 
and select the switch button with a key icon, to set it as the primary key
for the entity. Set the value class name to NSNumber and the external type to INTEGER

Add another entity, set the name and column names to 'name'.  
Select the switch button which looks like a jewel icon to set it as a Class Property. Set the Value Class Name to NSString and external type to TEXT.

now do the same with books, 
name them bookID, authorID, and title.
make sure bookID is set as the primary key not authorID in the books entity.
And that title is set as a class property.

title is a NSString/TEXT, where authorID and bookID are NSNumber/INTEGER

now add a relationship to authors
name it toBooks, and Tools, inspector
in the destination table, select To many, and books as the destination entity.

select authorID as the source and destination attributes

add a relationship to books, name it toAuthor.
Select author as the destination entity, and authorID as the source
and destination attributes.

The select Document, Save, from the main menu.

@node Project creation, Database creation, Model creation, Top
@chapter Creating a project.

@subsection Creating a makefile
Creating a GNUmakefile for a GDL2 Project is done throught he well documented
gnustep-make makefile system.

they are standard GNUmakefiles but you'll need to include a special file -- gdl2.make after common.make

E.g.
@example
include $(GNUSTEP_MAKEFILES)/common.make
include $(GNUSTEP_MAKEFILES)/Auxiliary/gdl2.make
@end example

@subsection Adding Resource Files
Make sure you add your .eomodel or .eomodeld file to your projects resources

@example
APP_NAME=foo
foo_RESOURCE_FILES=foo.eomodeld
@end example

@subsection A complete GNUmakefile 
@example
@verbatiminclude ../../Examples/example.GNUmakefile
@end example

@node Database creation, Database connection, Project creation, Top
@chapter Database creation
Now that we have created a model file, we need to generate the SQL to create the database.

@subsection Creating the database with DBModeler
Select, Generate SQL from the Tools menu, then
select the appropriate check boxes,

Create databases, Create tables, foreign key constraints, primary key constraints, and primary key support.

then either save the SQL to a file, or execute it, you may need to login to the database server, but the adaptor for the model should bring up a login panel.

@node Database connection, Working with data, Database creation, Top
@chapter Database connection

An example which connects to and then disconnects from the database.
provided you have already created the database in previous section

@example
@verbatiminclude ../../Examples/connection.m
@end example

@node Working with data, EOInterface, Database connection, Top
@chapter Working with data

@section Adding some data.
Here we have more complete example which writes a record to the database,
then fetches the record and updates it and saves the data again, then removes the record.

@example
@verbatiminclude ../../Examples/eoexample.m
@end example

@section Working with relationships
Heres another more complex example of working with data,
we'll add an author, and some books, and then traverse the relationship in
a couple of different ways.

@example
@verbatiminclude ../../Examples/eoexample2.m
@end example

@node EOInterface, Index, Working with data, Top
@chapter EOInterface
@section Introduction
With GDL2 and EOInterface you can develop graphical applications using the
gnustep gui libraries. It provides the ability to create connections
between records from the database, and graphical controls.

Once a connection has been made between the graphical control and the record,
EOInterface will update the record when the data changes in the control,
and update the control when the data or the selection changes.
EOInterface is composed of the EODisplayGroup class and EOAssociation
subclasses. 

EODisplayGroup contains the records and manages the selection,
and notifies EOAssociations when the selection or selected record changes.

EOAssociation subclasses, associate graphical controls to the display group
displaying the data in the display group, and updating the display group when
the control changes the data.  Multi-record associations such as table views can
change the display groups selection.

@section EODisplayGroup class
EODisplayGroup has an EODataSource, and can fetch and create objects, manage the
selection, filter the objects for display with qualifiers, and sort them with
EOSortOrderings. 

If you have loaded the GDL2Palette into Gorm you can create an EODisplayGroup
by dragging an entity or a relationship from the outline view in DBModeler,
to the document window in Gorm the display group will be associated with an
EODataSource and will be encoded/decoded to and from the .gorm file. It will be a top level object, visible in the 'Objects' view of the gorm document.
With the name of the entity or relationship dropped.

You can create connections from controls directly to the display group,
for example you could connect a button or menu item to EODisplayGroups
-selectNext: action by: 
Selecting the control and control-drag from the control to the display
group. In the connect inspector, select -selectNext: and click 'connect'.

Available actions for EODisplayGroup:
@enumerate
@item
-fetch:
@item
-selectNext:
@item
-selectPrevious:
@item
-delete:
@item
-insert:
@end enumerate

Manual creation of a EODisplayGroup by initializing the display group and
setting its dataSource:
@example
EODisplayGroup *dg;
EODataSource *dataSource;

dg = [[EODisplayGroup alloc] init];
[dg setDataSource:dataSource];
@end example

@section EOAssociation class
An EOAssociation is an abstract base class.
Subclasses of EOAssociation can be created to connect properties of an object
in an EODisplayGroup to graphical controls. EOControls contain aspects,
objects, and keys, and display groups.

Where the object is a graphical control, the key, being a key appropriate for 
KVC on an enterprise object, and the aspect is a string describing the
use for the key.  Each association has their own set of aspects and the aspects supported may vary between different association classes.

Manual creation of an EOControlAssocation:
@example
@verbatim
EOAssociation *association;
EODisplayGroup *authorDG;
NSTextField *nameField;

association = [[EOControlAssociation alloc] initWithObject:nameField];
[association bindAspect:@"value" displayGroup:authorDG key:@"name"];
[association establishConnection];
[association release];
@end verbatim
@end example

A few things of note, You can bind multiple aspects to an association.
When the connection is broken the association will be 
released.  When 'nameField' is deallocated, the connection will automatically
be broken.

EOAssociations can be created transparently by Gorm with the GDL2Palette.
To create an association with Gorm, Select a control and control-drag from a
control to an EODisplayGroup.  

In the connect inspector there is a pop up button which contains a list of the
association classes which are usable with the control. Select an association
class and the first column in the browser changes to a list of the aspects
available.  Selecting an aspect in the browser and the second column in the
browser will list the available class properties connectable to the aspect.

Unfortunately while not all association classes and aspects are
implemented.  They will unfortunately show up in the connect inspector.

@node Index, , EOInterface, Top
@unnumbered Index
     
@printindex cp

@bye