GDL2: the GNUstep Database Library
Then, we need to create our EOModel programmatically. The EOModel is a correspondence between data stored in the database and an enterprise object. It defines entities for the tables in the databases and their attributes and relationships that correspond to table columns. Listing 5 shows tool/model.m, the tool used to create our model used by our application. For sake of simplicity, the model of our small inventory application defines only one entity.
Listing 5. tool/model.m
#import <Foundation/Foundation.h>
#import <EOAccess/EOAccess.h>
int main(int arcg, char *argv[], char **envp)
{
NSAutoreleasePool *pool;
EOAttribute *theAttribute;
EOEntity *theEntity;
EOModel *theModel;
pool = [[NSAutoreleasePool alloc] init];
theEntity = [[EOEntity alloc] init];
[theEntity setName: @"Item"];
[theEntity setExternalName: @"INVENTORY"];
[theEntity setClassName: @"EOGenericRecord"];
theAttribute = [[EOAttribute alloc] init];
[theAttribute setName: @"iid"];
[theAttribute setColumnName: @"IID"];
[theAttribute setValueClassName: @"NSNumber"];
[theAttribute setExternalType: @"int4"];
[theEntity addAttribute: theAttribute];
[theEntity setPrimaryKeyAttributes:
[NSArray arrayWithObject:
theAttribute]];
[theEntity setAttributesUsedForLocking:
[NSArray arrayWithObject:
theAttribute]];
theAttribute = [[EOAttribute alloc] init];
[theAttribute setName: @"name"];
[theAttribute setColumnName: @"NAME"];
[theAttribute setValueClassName: @"NSString"];
[theAttribute setExternalType: @"varchar"];
[theAttribute setWidth: 255];
[theEntity addAttribute: theAttribute];
theAttribute = [[EOAttribute alloc] init];
[theAttribute setName: @"quantity"];
[theAttribute setColumnName: @"QUANTITY"];
[theAttribute setValueClassName: @"NSNumber"];
[theAttribute setExternalType: @"int4"];
[theEntity addAttribute: theAttribute];
theAttribute = [[EOAttribute alloc] init];
[theAttribute setName: @"order_date"];
[theAttribute setColumnName: @"ORDER_DATE"];
[theAttribute setValueClassName: @"NSCalendarDate"];
[theAttribute setExternalType: @"timestamp"];
[theEntity addAttribute: theAttribute];
[theEntity setClassProperties:
[theEntity attributes]];
theModel = [[EOModel alloc] init];
[theModel setName: @"Inventory"];
[theModel setAdaptorName: @"Postgres95"];
[theModel setConnectionDictionary:
[NSDictionary dictionaryWithObject:
@"inventory"
forKey:
@"databaseName"]];
[theModel addEntity: theEntity];
[theModel writeToFile: [theModel name]];
[pool release];
return EXIT_SUCCESS;
}
For our small inventory application, we use EOF's built-in EOGenericRecord class for our EOEntity object, which describes our inventory table. We easily could define our own Item class and use it instead of EOGenericRecord in order to provide, for example, automatic validation of values the object can accept through mutation methods. In Listing 5, we also specify the attribute mappings used for our EOEntity. For example, the iid attribute is mapped to our IID database column and corresponds to the entity's primary key. In addition, it is used for locking during updates. When a value is read from the database, which has an int4 type, EOF automatically creates a NSNumber instance holding the corresponding value. The same operations are done for the three other attributes to be fetched into the application: name, quantity and order_date. Before leaving the tool's main() function, we set the name of the adaptor to be used, Postgres95 in this example, and the database name. We then write the EOModel on disk.
To compile the tool, a small GNUmakefile must be created. Listing 6 is the GNUmakefile.
Listing 6. tool/GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
include $(GNUSTEP_MAKEFILES)/Auxiliary/gdl2.make
TOOL_NAME = model
model_OBJC_FILES = model.m
ADDITIONAL_OBJCFLAGS = -Wall -Wno-import
include $(GNUSTEP_MAKEFILES)/tool.make
after-clean::
rm -rf Inventory.eomodeld
after-distclean::
rm -rf inventory.eomodeld
Before running the test application, we first must run, only once, the tool that creates our EOModel. To do so, proceed with the following commands:
# cd tool # make # opentool shared_obj/model
This creates the Inventory.eomodeld directory, which holds all the information (the two plists) with regard to our EOModel. To compile and run our test application, proceed with the following commands:
# cd .. # make # openapp Inventory.app
Once the application has finished launching, -applicationDidFinishLaunching: is automatically invoked. In this method, we added the code to initialise EOF from our model. We also run the PostgreSQL's adaptor login panel (shown in Figure 3) in order to specify the user name/password and database name we want to use. In the future, GDL2 will offer the possibility to create databases directly from the login panel. For now, from this panel, enter inventory in the Username: and Database: fields, the password you assigned to the inventory user when creating it in the Password: field. Then, click on the Ok button.

Figure 3. Logging in to the inventory application
From the Inventory application, clicking on the Update button invokes the -update: method. In this method, we fetch all items from our database. Each item, which corresponds to a database row, is an instance of the EOGenericRecord class. Once EOF is done fetching the items, we reload our table view. Doing so automatically invokes -numberOfRowsInTableView: and -tableView:objectValueForTableColumn:row:. The former returns the number of fetched enterprise objects while the latter first gets the EOGenericRecord instance corresponding to the displayed row and returns the appropriate value for the table column using Key-Value-Coding (KVC).
Clicking on the Insert button calls the -insert: method in which we create an EOGenericRecord instance, set initial values (using KVC) and then register it to be inserted in our EOObjectStore. EOF automatically generates a unique ID, using the database sequence, and creates a database row. Finally, clicking on the Delete button invokes the -delete: method. In this method, we remove our enterprise object from the EOOjectStore, which removes the database row.
Live editing on the table view also is supported in our test application. The implementation of the -tableView:setObjectValue:forTableColumn:row: method offers us support for this functionality. In this method, we first obtain the enterprise object corresponding to our edited row. We then set the modified value to the right key, which is mapped to the right table column, based on our EOModel object.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
- Keeping track of IP address
22 min 38 sec ago - Roll your own dynamic dns
5 hours 36 min ago - Please correct the URL for Salt Stack's web site
8 hours 47 min ago - Android is Linux -- why no better inter-operation
11 hours 2 min ago - Connecting Android device to desktop Linux via USB
11 hours 31 min ago - Find new cell phone and tablet pc
12 hours 29 min ago - Epistle
13 hours 58 min ago - Automatically updating Guest Additions
15 hours 6 min ago - I like your topic on android
15 hours 53 min ago - This is the easiest tutorial
22 hours 29 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Re: GDL2: the GNUstep Database Library
Interesting article.
At this moment, this site at this link doesn't seem to exist:
And for the Python-inclined, there is a EOF-inspired Object-Relational database bridge called "Modeling" at: