Using Ruby on Rails with legacy Oracle databases

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites

    Using Ruby on Rails with legacy Oracle databases - Presentation Transcript

    1. Using Ruby on Rails with legacy Oracle databases Raimonds Simanovskis
    2. Ruby => Oracle require 'oci8' Ruby application OCI8.new('scott', 'tiger').exec( 'select * from emp') do |r| puts r.join(',') end ruby-oci8 Oracle Instant Oracle Database Client SQL*Net
    3. JRuby => Oracle require \"java\" sql = Ruby application JavaSQL::DriverManager.getConnec tion(db, user, password) statement = sql.createStatement status = statement.execute \"select * from parts;\" JRuby rs = statement.getResultSet() JDBC driver Oracle Database SQL*Net
    4. ActiveRecord Oracle Enhanced Adapter
    5. Ruby on Rails 2.x => Oracle gem install activerecord-oracle_enhanced-adapter database.yml development: adapter: oracle_enhanced database: XE username: blogdemo password: blogdemo encoding: utf8
    6. SQL bind variables database.yml Employee.find(1) development: ActiveRecord adapter: oracle_enhanced SELECT * FROM employees database: XE WHERE (employees.id = 1) username: blogdemo password: blogdemo Oracle optimizer encoding: utf8 SELECT * FROM employees WHERE cursor_sharing: similar (employees.id = :SYS_B_0)
    7. 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 True/FalseClass :boolean NUMBER(1), CHAR(1)
    8. Workarounds ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter. emulate_dates_by_column_name = true hire_date # Oracle DATE => Ruby Date hire_time # Oracle DATE => Ruby Time set_date_columns :started_on, :finished_on set_datetime_columns :start_date_and_time, :end_date_and_time ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter. emulate_booleans_from_strings = true active_flag # Oracle CHAR(1) ‘Y’/’N’ => true/false set_boolean_columns :some_boolean_column ignore_table_columns :attribute1, :attribute2
    9. Calling PL/SQL from Ruby 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
    10. ruby-plsql gem gem install ruby-plsql require \"ruby-plsql\" plsql.connection = OCI8.new(\"hr\",\"hr\",\"xe\") puts plsql.test_uppercase('xxx')
    11. ruby-plsql gem plsql.connection = OCI8.new(\"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
    12. class Employee < ActiveRecord::Base set_create_method do plsql.employees_pkg.create_employee( :p_first_name => first_name, :p_last_name => last_name, :p_employee_id => nil Custom )[:p_employee_id] end set_update_method do CUD plsql.employees_pkg.update_employee( :p_employee_id => id, :p_first_name => first_name, methods ) end :p_last_name => last_name set_delete_method do plsql.employees_pkg.delete_employee( :p_employee_id => id ) end end
    13. Other features • composite_primary_keys support • NLS_DATE_FORMAT independent • TIMESTAMP columns support • Faster schema dump
    14. DEMO see code at http://github.com/rsim/legacy_oracle_sample
    15. Ruby on Rails application Controller classes (incoming request HTTP request processing) Browser HTML result Model classes View templates (business logic) (HTML, Javascript) Ruby on SQL update data selects through API SQL Rails on Oracle Oracle E-Business Suite database new schema for web application custom tables synonym for for web views EBS application synonym for packages APPS schema XXX schema custom views for data read data XXX tables access update data custom or standard API packages
    16. HTTPS Application server Apache Typical HTTP HAproxy balancer application HTTP HTTP HTTP server Mongrel Mongrel ... Mongrel TCP TCP TCP processes SQL SQL SQL Memcached Oracle DB
    17. Thank You! http://blog.rayapps.com http://github.com/rsim

    + rsimrsim, 2 years ago

    custom

    2886 views, 3 favs, 3 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2886
      • 2619 on SlideShare
      • 267 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 36
    Most viewed embeds
    • 258 views on http://blog.rayapps.com
    • 8 views on http://theappslab.com
    • 1 views on http://74.125.93.132

    more

    All embeds
    • 258 views on http://blog.rayapps.com
    • 8 views on http://theappslab.com
    • 1 views on http://74.125.93.132

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories