Fast Web Applications Development with Ruby on Rails on Oracle
Upcoming SlideShare
Loading in...5

Fast Web Applications Development with Ruby on Rails on Oracle






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Fast Web Applications Development with Ruby on Rails on Oracle Fast Web Applications Development with Ruby on Rails on Oracle Presentation Transcript

  • Fast Web Applications Development with Ruby on Rails on Oracle
  • Raimonds Simanovskis rsim
  • What is Ruby on Rails?
  • Ruby is object-oriented dynamic programming language simple from outside Yukihiro Matsumoto or “Matz” powerful inside
  • Ruby on Rails Web applications development framework Developed in Ruby Extracted from 37signals Basecamp application Open source software Focused on developer productivity Agile software development approach
  • Main principles DRY - Don’t Repeat Yourself Convention over Configuration Opinionated software
  • MVC Architecture Request Router Database Browser Response Action Active Controller Record Action View
  • Active Record (Model) class CreatePosts < ActiveRecor::Migration def self.up create_table :posts do |t| CREATE TABLE posts ( t.string :title id NUMBER(38) NOT t.text :body NULL, t.timestamps title VARCHAR2(255), end body CLOB, end created_at DATE, end updated_at DATE ); CREATE SEQUENCE posts_seq; class Post < ActiveRecord::Base # nothing here! end post = post.title = "First post" post = Post.find(1) puts # output: "First post"
  • Action Controller class PostsController < ApplicationController def index @posts = Post.all end def show @post = Post.find(params[:id]) end def new @post = end # ... end
  • Action View <h1>Posts</h1> <% @posts.each do |post| %> <h2><%= post.title %></h2> <h3>Created at <%= post.created_at %></h3> <p><%= post.body %></p> <% end %>
  • Demo
  • Ruby platforms MRI 1.8.7 Ruby/YARV JRuby 1.9.2 Rubinius IronRuby MacRuby MagLev BlueRuby
  • Ruby => Oracle Ruby application require 'oci8''scott', 'tiger').exec( 'select * from emp') do |r| puts r.join(',') end ruby-oci8 Oracle [Instant] Oracle Database Client SQL*Net
  • JRuby => Oracle Ruby application require "java" java.sql.DriverManager.registerDriver( conn = java.sql.DriverManager.getConnection( 'jdbc:oracle:thin:orcl', 'hr', 'hr') statement = conn.createStatement JRuby status = statement.execute( "SELECT * FROM employees") rs = statement.getResultSet() JDBC driver Oracle Database SQL*Net
  • ActiveRecord Oracle enhanced adapter
  • Ruby on Rails => Oracle gem install activerecord-oracle_enhanced-adapter database.yml development: adapter: oracle_enhanced database: orcl username: blog password: blog
  • Multi-platform support oracle_enhanced adapter Ruby 1.8.7 Ruby 1.9.2 JRuby ruby-oci8 ruby-oci8 JDBC
  • Oracle Data Types Ruby Rails Oracle Fixnum :integer NUMBER Float :float NUMBER BigDecimal :decimal NUMBER, DECIMAL Time :datetime DATE Time :time DATE Date :date DATE String :string VARCHAR2 String :text CLOB String :binary BLOB True/FalseClass :boolean NUMBER(1), CHAR(1)
  • Legacy schemas class Employee < ActiveRecord::Base set_table_name "hr_employees" set_primary_key "employee_id" set_sequence_name "hr_employee_s" set_date_columns :hired_on, :birth_date_on set_datetime_columns :last_login_time set_boolean_columns :manager, :active ignore_table_columns :attribute1, :attribute2 end
  • DataMapper Alternative Ruby ORM persistence framework Not just for relational databases
  • DataMapper Model class Post include DataMapper::Resource property :id, Serial property :title, String, :length => 255, :nullable => false property :body, Text timestamps :at CREATE TABLE posts ( end id NUMBER(38) NOT NULL PRIMARY KEY, title VARCHAR2(255) NOT NULL, created_at DATE, updated_at DATE ); CREATE SEQUENCE posts_seq; CREATE TRIGGER posts_pkt post = ...; post.title = "First post" post = Post.get(1) puts # output: "First post"
  • PL/SQL calls from Ruby (old way) require "oci8" conn ="hr","hr","xe") cursor = conn.parse <<-EOS BEGIN :return := test_uppercase(:p_string); END; EOS cursor.bind_param(':p_string',"xxx",String) cursor.bind_param(':return',nil,String,4000) cursor.exec puts cursor[':return'] cursor.close
  • ruby-plsql gem gem install ruby-plsql require "ruby-plsql" plsql.connect! "hr","hr","xe" puts plsql.test_uppercase('xxx')
  • ruby-plsql gem plsql.connect! "hr","hr","xe" plsql.test_uppercase('xxx') # => "XXX" plsql.test_uppercase(:p_string => 'xxx') # => "XXX" plsql.test_copy("abc", nil, nil) # => { :p_to => "abc", # :p_to_double => "abcabc" } plsql.test_copy(:p_from => "abc", :p_to => nil, :p_to_double => nil) # => { :p_to => "abc", # :p_to_double => "abcabc" }'xxx') # => "XXX" plsql.test_package.test_uppercase('xxx') # => 'XXX''xxx') # => 'XXX' plsql.logoff
  • class Employee < ActiveRecord::Base set_create_method do plsql.employees_pkg.create_employee( :p_first_name => first_name, ActiveRecord :p_last_name => last_name, :p_employee_id => nil )[:p_employee_id] with end set_update_method do PL/SQL plsql.employees_pkg.update_employee( :p_employee_id => id, :p_first_name => first_name, CRUD ) :p_last_name => last_name procedures end set_delete_method do plsql.employees_pkg.delete_employee( :p_employee_id => id ) end end
  • Java integration with JRuby require "java" java.lang.System.current_time_millis # => java.lang.System.currentTimeMillis() import java.lang.System['java.runtime.version'] # => System.getProperties[...] System.err = System.out # => System.setErr(System.getOut) import javax.swing.JFrame import javax.swing.JButton f ="Swing Demo") f.set_size 400, 300 f.layout = button ="Hello world!") f.add(button)
  • Full-text indexes add_context_index :posts, [:title, :body, # specify aliases always with AS keyword "SELECT AS comment_author, " + "comments.body AS comment_body " + "FROM comments WHERE comments.post_id = :id" ], :name => 'post_and_comments_index', :index_column => :all_text, :index_column_trigger_on => [:updated_at, :comments_count], :sync => 'ON COMMIT' Post.contains(:all_text, "hello") Post.contains(:all_text, "{first} within title") Post.contains(:all_text, "{first} AND {post}")
  • Deployment options Application source Apache Java app sever Application WAR file Ruby mod_passenger JRuby Gems Application Application
  • Why Rails on Oracle? Fast agile / iterative development Test-driven development support Flexible HTML/CSS/JavaScript front-end Easy to put on top of legacy applications Libraries for all new “cool” technologies Open-source with liberal license
  • More information
  • Related sessions Session ID: S318545 Develop a Ruby on Rails Web Application with Title: Oracle Database 11g in One Hour Thursday, September 23, 12:30 | Hilton San Schedule: Francisco, Franciscan A / B / C / D Session ID: S319104 Title: PL/SQL Unit Testing Can Be Fun! Tuesday, September 21, 09:30 | Hotel Nikko, Schedule: Bay View
  • JRuby meetup Tuesday, September 21 5:30 - 7:00 Networking + beer + food 7:00 - 8:00 Lightning talks @ Engine Yard 500 3rd Street, Suite 510