
Session: F04 DB2 On Rails Philip Nelson ScotDB Limited Monday May 7th, 2007 : 16:20 - 17:20. Platform: DB2 for Linux, UNIX and Windows Presentation F04 : DB2 on Rails This presentation examines using DB2 with the Ruby on Rails web framework. Presenter's Biography Philip Nelson has worked with DB2 for z/OS since 1989 and with DB2 on distributed platforms since OS/2 Extended Services acquired a Database Manager component. On a daily basis he administers DB2 for z/OS, DB2 for AIX, DB2 for Solaris and IMS databases for a large financial organisation in the United Kingdom. He is also the Database Technology Architect within this company. In addition he is a principal of ScotDB Limited, a consultancy company focused on the SMB market and specializing in DB2 on the Linux platform. Over a number of years he has been central to delivering successful projects for customers in a range of industries. He has also produced and delivered both in house and public training courses on DB2 and related technologies. He has been involved with IDUG since 1999 and currently is deputy editor of IDUG Solutions Journal. 1 AGENDA • Introduction to Ruby • Introduction to Ruby on Rails • Integrating Ruby on Rails with DB2 • Developing a Ruby on Rails Application • Using Ruby on Rails with Legacy Databases • Deploying Ruby on Rails Applications • Improving DB2 support for Ruby on Rails • Ruby on Rails resource directory 2 Agenda Firstly we will provide a brief introduction to the Ruby programming language. before looking at the Ruby on Rails web framework and why it is “special”. Then we will start exploring how DB2 can be used with Ruby on Rails (RoR). We'll show how to enable RoR to use DB2 as its persistance (database backend) layer. We will concentrate on the ibm_db2 driver developed by IBM. Then we will demonstrate how to develop a RoR application, firstly in a “green field” development and then using an existing “legacy” database. We will describe the process all the way from initial project setup to production deployment. Along the way we will point out problems encountered and the most critical “areas for improvement” within the DB2 support. We will finish up a list of resources for RoR developers. 2 What is Ruby ? z A programming language z Interpreted z Object Oriented z Developed in Japan in the mid 90s (first public release in 1995) by Yakihiro Matsumoto (“Matz”) z Really became popular in the wider world with the introduction of Ruby on Rails 3 Ruby is an open source, interpreted, object-oriented programming language, developed by Yakihiro Matsumoto (nickname and online handle “Matz”) in the mid 1990s. The first public release was in 1995. However it was virtually unknown outside Japan until David Heinemeier Hansson developed the Ruby on Rails web framework using Ruby as the programming language. 3 What is Ruby on Rails ? z Web development framework z Developed by David Heinemeier Hansson z Came out of his work on developing the Basecamp web-based product (http://www.basecamphq.com) z Uses Ruby as the underlying language z Based on the MVC paradigm z Model : the information layer z View : the display layer z Controller : the business logic layer 4 Ruby on Rails is a web development framework based on the MVC (model, view, controller) paradigm. Its initial creator was David Heinemeir Hansson. David was heavily involved in the creation of a web-based collaboration product called Basecamp (http://www.basecamphq.com). The underlying framework he developed while writing Basecamp formed the basis of Ruby on Rails. There are many development tools, both for web-based and traditional client-server deployment, based on the MVC paradigm. The underlying idea is to separate display (View), business logic (Controller) and data access (Model) and thus make the application easier to maintain. Unfortunately many of these tools rely on complex configuration files to tie the three parts together. The Java-based J2EE framework, in particular, become so huge in J2EE 1.4 that there was virtually a “revolt” among developers against the complexity : later releases has sought to simplify things, with such initiatives as allowing POJO (Plain Old Java Objects) to be used instead of requiring an application to always produce EJBs (Enterprise Java Beans). But still the complexity is greater than many people can cope with. 4 Why is Rails “special” ? z Speed of development z Built-in support for testing z Database support : “migrations” z “Convention over Configuration” z Greatly reduces the overhead of creating software z Most benefit if willing to conform to conventions z Can be overridden if required 5 Ruby on Rails seeks to eliminate much of the configuration file headache by emphasizing “Convention over Configuration”. The idea is that as long as a developer is willing to use the default behaviours for connecting the different parts of an application together there should be little or no need to set up and maintain configuration files. The challenge is to choose sensible default behaviours which meet a wide range of requirements. Because the framework enforced these defaults unless they are overridden explicitly, RoR is sometimes described as “opinionated”. The greatest benefit is therefore obtained when all the conventions are followed, which often means in “green field” (totally new) developments. While it is possible to successfully use RoR for development within an existing “legacy” environment, the further existing data models vary from the Rails conventions the less benefit can be obtained. Other interesting concepts within the RoR framework are extensive support for automated testing and maintenance of database schemas within the application development framework. 5 Rails Components • Rails draws on a number of Ruby modules • Active Support : common libraries • Rake : Ruby “make” • Active Record : model (ORM) • Action Pack : two closely coupled modules • ActionController • ActionView • Action Mailer : email support • Action Web Service (will be a separate plugin in Rails 2.0, due to REST support added in 1.2) • Rails itself is underneath, orchestrating interactions 6 Rails draws on a number of Ruby Gems (modules) to provide essential services. At the core of these are Active Record, which provides the Object-Relational Mapping (ORM) support at the heart of the “model” element. The “controller” and “view” components are supplied by Action Pack, which actually contains two closely couple modules, ActionController and ActionView. There is also a library of commonly used libraries (Active Support), a module to automate tasks (Rake = Ruby Make), a module providing email services (Action Mailer) and a module provide XML-RPC and SOAP web service support (Action Web Service or AWS). The last of these will become an optional plugin to Rails 2.0, since it is considered that this support is not strictly required any more (Rails 1.2 added REST support and this is considered preferable in many circumstances). Most of our interactions with Rails happen at the level of these modules. Rails itself sits underneath, orchestrating everything. 6 Where does DB2 fit in ? z DB2 “adapter” (driver) from IBM z Called ibm_db2 (there already is a non-IBM db2 adapter) z Download from Alphaworks z http://www.alphaworks.ibm.com/tech/db2onrails z Very active community around it z There is also another driver, not developed by IBM z http://raa.ruby-lang.org/project/ruby-db2 z We will concentrate on the IBM driver here 7 RoR has gained popularity very quickly, and has acquired a very dedicated following. Thankfully there are folks within IBM who “caught the wave” and have set out to try to make support for DB2 as good as possible. As we shall see there is still a lot of work to be done. Before IBM became involved, an open source project had done some work to provide DB2 support, within the Ruby DBI framework. This seems to have progressed at a fairly leisurely pace and the IBM-developed support appears to have overtaken this very quickly. So in this presentation we will concentrate on using the IBM-developed support (called ibm_db2) available for download from IBM Alphaworks. 7 Getting Rails Running (Summary) z Install Ruby language support z Install Gems support z Ruby “Gems” are the names given to add-on packages for Ruby z Package manager command line called “gem” z Install Rails Gem z Windows package includes Ruby, Gem and Rails 8 Before we can start trying to make DB2 work with RoR, we need to actually get RoR up and running. There are number of steps involved in this. First we have to ensure we have the Ruby language available. Then we install a facility for managing Ruby Gems. Gems are a collection of add-on packages for Ruby : in many ways similar to the Perl modules available through CPAN (Comprehensive Perl Archive Network). RoR is packaged as a Ruby Gem, as do all the prerequisites. There are packages available for a number of environments which package Ruby, Gem and Rails together for easy installation. This is particularly necessary in the Microsoft Windows environment, where not everyone has easy access to the C compiler which is required to build Ruby and some gems from source. 8 Installing Ruby Language Support • Source code available from http://www.ruby- lang.org • Prebuilt packages available for - • Windows (installer from site above) • Linux (packages for most distributions) • All work for this presentation on OpenSuSE 10.2 • Packages ruby-1.8.5-18 and ruby-devel-1.8.5-18 • Macintosh OS-X (multiple options from site above) 9 The Ruby language is open source, and the source code can be downloaded from http://www.ruby-lang.org : build facilities are available for a wide range of environments.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages76 Page
-
File Size-