Your SlideShare is downloading. ×
0
Fast
Web Applications
   Development
with Ruby on Rails
     on Oracle
Raimonds Simanovskis

github.com/
    rsim
What is
Ruby on
 Rails?
Ruby is
                object-oriented
                   dynamic
             programming language
              simple ...
Ruby on Rails
  Web applications development framework

             Developed in Ruby

Extracted from 37signals Basecamp ...
Main principles
DRY - Don’t Repeat Yourself

Convention over Configuration

    Opinionated software
MVC Architecture
              Request    Router      Database


Browser
  Response




                         Action   ...
Active Record (Model)
class CreatePosts < ActiveRecor::Migration
  def self.up
    create_table :posts do |t|   CREATE TAB...
Action Controller
class PostsController < ApplicationController
  def index
    @posts = Post.all
  end

 def show
   @pos...
Action View

<h1>Posts</h1>
<% @posts.each do |post| %>
  <h2><%= post.title %></h2>
  <h3>Created at <%= post.created_at ...
Demo
Ruby platforms
MRI 1.8.7


Ruby/YARV
              JRuby
  1.9.2


                      Rubinius   IronRuby   MacRuby



...
Ruby => Oracle
  Ruby application           require 'oci8'
                             OCI8.new('scott', 'tiger').exec(
 ...
JRuby => Oracle
Ruby application   require "java"
                   java.sql.DriverManager.registerDriver(
              ...
ActiveRecord
Oracle enhanced
    adapter
Ruby on Rails
             => Oracle
gem install activerecord-oracle_enhanced-adapter


database.yml
development:
  adapte...
Multi-platform support
        oracle_enhanced adapter




 Ruby 1.8.7       Ruby 1.9.2      JRuby

 ruby-oci8        ruby...
Oracle Data Types
    Ruby            Rails             Oracle
    Fixnum          :integer        NUMBER
     Float      ...
Legacy schemas
class Employee < ActiveRecord::Base
  set_table_name "hr_employees"
  set_primary_key "employee_id"
  set_s...
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 =...
PL/SQL calls from Ruby
      (old way)
 require "oci8"
 conn = OCI8.new("hr","hr","xe")

 cursor = conn.parse <<-EOS
 BEGI...
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_...
class Employee < ActiveRecord::Base
             set_create_method do
               plsql.employees_pkg.create_employee(
...
Java integration with
       JRuby
 require "java"
 java.lang.System.current_time_millis
   # => java.lang.System.currentT...
Full-text indexes
add_context_index :posts,
  [:title, :body,
  # specify aliases always with AS keyword
  "SELECT comment...
Deployment options
                         Application source




        Apache                                   Java a...
Why Rails on Oracle?
   Fast agile / iterative development
   Test-driven development support
Flexible HTML/CSS/JavaScript...
More information
         http://blog.rayapps.com


 http://github.com/rsim/oracle-enhanced


http://groups.google.com/gro...
Related sessions
Session ID: S318545
            Develop a Ruby on Rails Web Application with
Title:
            Oracle Da...
JRuby meetup
      Tuesday, September 21

5:30 - 7:00 Networking + beer + food
7:00 - 8:00 Lightning talks


         @ En...
Upcoming SlideShare
Loading in...5
×

Fast Web Applications Development with Ruby on Rails on Oracle

3,205

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,205
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
34
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Fast Web Applications Development with Ruby on Rails on Oracle"

  1. 1. Fast Web Applications Development with Ruby on Rails on Oracle
  2. 2. Raimonds Simanovskis github.com/ rsim
  3. 3. What is Ruby on Rails?
  4. 4. Ruby is object-oriented dynamic programming language simple from outside Yukihiro Matsumoto or “Matz” powerful inside
  5. 5. 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
  6. 6. Main principles DRY - Don’t Repeat Yourself Convention over Configuration Opinionated software
  7. 7. MVC Architecture Request Router Database Browser Response Action Active Controller Record Action View
  8. 8. 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.new post.title = "First post" post.save post = Post.find(1) puts post.name # output: "First post"
  9. 9. Action Controller class PostsController < ApplicationController def index @posts = Post.all end def show @post = Post.find(params[:id]) end def new @post = Post.new end # ... end
  10. 10. 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 %>
  11. 11. Demo
  12. 12. Ruby platforms MRI 1.8.7 Ruby/YARV JRuby 1.9.2 Rubinius IronRuby MacRuby MagLev BlueRuby
  13. 13. Ruby => Oracle Ruby application require 'oci8' OCI8.new('scott', 'tiger').exec( 'select * from emp') do |r| puts r.join(',') end ruby-oci8 Oracle [Instant] Oracle Database Client SQL*Net
  14. 14. JRuby => Oracle Ruby application require "java" java.sql.DriverManager.registerDriver( Java::oracle.jdbc.driver.OracleDriver.new) 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
  15. 15. ActiveRecord Oracle enhanced adapter
  16. 16. Ruby on Rails => Oracle gem install activerecord-oracle_enhanced-adapter database.yml development: adapter: oracle_enhanced database: orcl username: blog password: blog
  17. 17. Multi-platform support oracle_enhanced adapter Ruby 1.8.7 Ruby 1.9.2 JRuby ruby-oci8 ruby-oci8 JDBC
  18. 18. 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)
  19. 19. 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
  20. 20. DataMapper Alternative Ruby ORM persistence framework Not just for relational databases
  21. 21. 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.new ...; post.title = "First post" post.save post = Post.get(1) puts post.name # output: "First post"
  22. 22. PL/SQL calls from Ruby (old way) require "oci8" conn = OCI8.new("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
  23. 23. ruby-plsql gem gem install ruby-plsql require "ruby-plsql" plsql.connect! "hr","hr","xe" puts plsql.test_uppercase('xxx')
  24. 24. 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" } plsql.hr.test_uppercase('xxx') # => "XXX" plsql.test_package.test_uppercase('xxx') # => 'XXX' plsql.hr.test_package.test_uppercase('xxx') # => 'XXX' plsql.logoff
  25. 25. 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
  26. 26. Java integration with JRuby require "java" java.lang.System.current_time_millis # => java.lang.System.currentTimeMillis() import java.lang.System System.properties['java.runtime.version'] # => System.getProperties[...] System.err = System.out # => System.setErr(System.getOut) import javax.swing.JFrame import javax.swing.JButton f = JFrame.new("Swing Demo") f.set_size 400, 300 f.layout = java.awt.FlowLayout.new button = JButton.new("Hello world!") f.add(button) f.show
  27. 27. Full-text indexes add_context_index :posts, [:title, :body, # specify aliases always with AS keyword "SELECT comments.author 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}")
  28. 28. Deployment options Application source Apache Java app sever Application WAR file Ruby mod_passenger JRuby Gems Application Application
  29. 29. 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
  30. 30. More information http://blog.rayapps.com http://github.com/rsim/oracle-enhanced http://groups.google.com/group/oracle-enhanced
  31. 31. 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
  32. 32. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×