GDL2: the GNUstep Database Library
Some of my previous articles presented the Graphical Object Relationship Modeler (Gorm) and Renaissance, two important projects for GNUstep. This article aims to provide a short introduction to GDL2—the GNUstep Database Library. While this article focuses on GDL2, the reader is encouraged to read previous GNUstep articles, (Linux Journal, April 2003 and March 2004) for a better understanding of Gorm and of the Objective-C language.
GDL2 is a free (LGPL) implementation of EOF, Enterprise Objects Framework. EOF was created by NeXT Computer, Inc. in 1994 as a collection of API to develop efficiently object-oriented database applications using the Objective-C language. It evolved from a lower-level framework, known as DB Kit, that was available on NeXTSTEP. Apple's implementations of EOF now are based on the Java language, leaving Objective-C developers with no choices but to consider rewriting their applications in Java or looking at a free implementation of EOF. GDL2 is aimed at compatibility with version 4.5 of EOF.
EOF is divided into multiple layers: EOAccess, EOControl and EOInterface. The role of the former is to transfer data from the RDBMS to enterprise objects and from objects to raw database data. EOControl is used to maintain an in-memory graph of enterprise objects and delegate modifications to the database using EOAccess. EOInterface is used to map enterprise objects to user interface elements. Unfortunately, EOInterface is not yet implemented in GDL2. Figure 1 presents the various layers, how they relate to Foundation, AppKit and how they relate in a typical client/server AppKit application that makes use of EOF.
Furthermore, EOF allows developers to create database-oriented applications without writing any SQL. Instead, the developers concentrate on manipulating real objects. In addition, when synchronizing changes made to objects with the database, EOF has mechanisms to validate, enforce referential integrity, generate primary and foreign keys, manage transactions and provide locking—either pessimistic, optimistic or on-demand—to ensure integrity of the data thus, removing entirely this burden from the application developers.
The source code of the test application and all listings, fully commented, are available from the Linux Journal FTP site (see the on-line Resources section). You should refer to this source code for a better understanding of all listings shown in this article.
In order to install GDL2 and create our test application, we first must install GNUstep and Gorm. Furthermore, we need to install PostgreSQL because we are using the Postgres95 EOF adaptor in our example.
The latest stable release is always recommended. For this project, this includes GNUstep make 1.9.1, GNUstep base 1.9.1, GNUstep GUI 0.9.2, GNUstep back 0.9.2, Gorm 0.7.5 and PostgreSQL 7.4.2. When installing PostgreSQL, be sure to install the development packages for libpq header files, as they are required in order to compile GDL2. Debian provides the postgresql-dev package while Red Hat provides the postgresql-devel package. Once the requirements are installed, proceed with the following commands:
# wget ftp://ftp.gnustep.org/pub/gnustep/libs/gdl2-0.9.1.tar.gz # tar -zxvf gdl2-0.9.1.tar.gz # cd gdl2-0.9.1 # ./configure # makeAnd finally, as root:
# make installThis will download GDL2 v0.9.1 from the GNUstep FTP server, compile and install it.
In the first GNUstep article, the Model-View-Controller (MVC) design pattern was introduced. When using EOF, much of the controller's logic described in the previous article now is being managed automatically by EOF. In fact, the application's user interface becomes the View, EOF the controller and database itself, the Model.
In this article, we create a trivial inventory management application that makes use of the MVC model. This application displays a window, a table view showing the inventory items and three buttons used to update the inventory, insert or delete a new item. Before creating the application, we need to create our inventory database and the credentials we will use in our test application. To do so, proceed with the following commands:
% su - postgres % createuser --pwprompt inventory Enter password for user "inventory": (specify a password) Enter it again: Shall the new user be allowed to create databases? (y/ n) y Shall the new user be allowed to create more new users? (y/ n) n CREATE USER % createdb -O inventory inventory CREATE DATABASE
Once the database and the user are created, we next create the sequence and table used by our test application. Be sure the authentication mechanisms in PostgreSQL are configured well before using the psql tool:
% psql -U inventory inventory create sequence inventory_seq start with 1; create table inventory ( iid int4, name varchar(255), quantity int4, order_date timestamp, primary key (iid) );
Once the steps related to the database are completed, we now proceed, with Gorm, to create the user interface for the inventory application. To do so, open the modeler and from the Document menu, choose New Application. From the Inspector window, set the window title to Inventory. Then, from the Palettes window, drag a NSTableView object to the application's window and insert a third table column using copy/paste. Set the table columns' titles to Name, Quantity and Order Date. Also, set the table column identifiers to name, quantity and order_date respectively. Then, drag three buttons from the Palettes window to the application's window and set their respective title to Update, Insert and Delete.
From the File window, click on the Classes icon and select the NSObject item. From the Classes menu, choose Create Subclass.... Rename the controller class to AppController and create the window and tableView outlets. Furthermore, insert:, delete: and update: actions must be added. Once we have created the outlets and actions, we are ready to instantiate our controller class. Do so and then connect the window and tableView outlets, set the delegate/datasource on the tableview and the delegate/windowController on the window to our application's controller.
Furthermore, connect the actions on the buttons. From the Document menu, choose Save... and specify the name MainMenu.gorm. Additionally, connect the NSOwner's delegate outlet to AppController. Finally, from the Classes view, select AppController and create the class files (AppController.h and AppController.m). Overall, the user interface should look like Figure 2.
Once the user interface has been created, open AppController.h in your favorite editor and add the items and editingContext instance variables, as shown in Listing 1. Then, modify AppController.m in order to implement the -delete:, -insert: and -update: methods. Furthermore, you need to add the -init, -dealloc, -numberOfRowsInTableView, -tableView:objectValueForTableColumn:row:, -tableView:setObjectValue:forTableColumn:row:, -applicationDidFinishLaunching: methods as well as the application entry point, main() and the required #import directives for EOF headers. Listing 2 shows the complete source of the application's controller. A description of all methods is provided in the next section.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
- Doing for User Space What We Did for Kernel Space
- Tech Tip: Really Simple HTTP Server with Python
- SuperTuxKart 0.9.2 Released
- Parsing an RSS News Feed with a Bash Script
- Rogue Wave Software's Zend Server
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide