Ruby on Rails Oracle adaptera izstrāde

1,247 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
1,247
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby on Rails Oracle adaptera izstrāde

  1. 1. + Ruby on Rails Oracle adaptera izstrāde
  2. 2. Raimonds Simanovskis TietoEnator Alise
  3. 3. Kas ir Ruby on Rails?
  4. 4. Ruby ir objektorientēta dinamiska programmēšanas valoda vienkārša pēc izskata spēcīgas iespējas
  5. 5. Ruby on Rails Moderns “tīmekļa lietojumu ietvars” Veidots Ruby programmēšanas valodā Radies no 37signals Basecamp aplikācijas Atvērtā koda programmatūra Fokusējas uz izstrādātāju produktivitāti Spējā (Agile) programmatūras izstrādes pieeja
  6. 6. Pamatprincipi Neatkārto sevi DRY - Don’t Repeat Yourself Vienošanās nevis konfigurēšana Convention over Configuration Programmatūra ar viedokli Opinionated software
  7. 7. Komponentes
  8. 8. Active Record (Model)
  9. 9. Action Controller
  10. 10. Action View
  11. 11. Ruby platformas MRI 1.8.6 Ruby/YARV JRuby 1.9.1 Rubinius IronRuby MacRuby MagLev BlueRuby
  12. 12. 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
  13. 13. JRuby => Oracle require quot;javaquot; sql = Ruby application JavaSQL::DriverManager.getConnec tion(db, user, password) statement = sql.createStatement status = statement.execute quot;select * from parts;quot; JRuby rs = statement.getResultSet() JDBC driver Oracle Database SQL*Net
  14. 14. ActiveRecord Oracle Enhanced Adapter
  15. 15. Ruby on Rails => Oracle gem install activerecord-oracle_enhanced-adapter database.yml development: adapter: oracle_enhanced database: XE username: blogdemo password: blogdemo encoding: utf8
  16. 16. SQL bind variables Employee.find(1) database.yml development: ActiveRecord adapter: oracle_enhanced SELECT * FROM employees database: XE WHERE (employees.id = 1) username: blogdemo Oracle optimizer password: blogdemo encoding: utf8 SELECT * FROM employees WHERE cursor_sharing: similar (employees.id = :SYS_B_0)
  17. 17. 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)
  18. 18. Citi ierobežojumi Identifikatori līdz 30 lēni Data Dictionary skatījumi simboliem CLOB / BLOB izmantošana tukšs String == NULL SQL pieprasījumos Oracle XE nav uz Mac OS X LIMIT, OFFSET neesamība
  19. 19. Multi platformu atbalsts oracle_enhanced adapter Ruby/YARV MRI 1.8.6 JRuby 1.9.1 ruby-oci8 1.x ruby-oci8 2.x JDBC
  20. 20. PL/SQL izsaukšana no Ruby require quot;oci8quot; conn = OCI8.new(quot;hrquot;,quot;hrquot;,quot;xequot;) cursor = conn.parse <<-EOS BEGIN :return := test_uppercase(:p_string); END; EOS cursor.bind_param(':p_string',quot;xxxquot;,String) cursor.bind_param(':return',nil,String,4000) cursor.exec puts cursor[':return'] cursor.close
  21. 21. ruby-plsql gem gem install ruby-plsql require quot;ruby-plsqlquot; plsql.connection = OCI8.new(quot;hrquot;,quot;hrquot;,quot;xequot;) puts plsql.test_uppercase('xxx')
  22. 22. ruby-plsql gem plsql.connection = OCI8.new(quot;hrquot;,quot;hrquot;,quot;xequot;) plsql.test_uppercase('xxx') # => quot;XXXquot; plsql.test_uppercase(:p_string => 'xxx') # => quot;XXXquot; plsql.test_copy(quot;abcquot;, nil, nil) # => { :p_to => quot;abcquot;, # :p_to_double => quot;abcabcquot; } plsql.test_copy(:p_from => quot;abcquot;, :p_to => nil, :p_to_double => nil) # => { :p_to => quot;abcquot;, # :p_to_double => quot;abcabcquot; } plsql.hr.test_uppercase('xxx') # => quot;XXXquot; plsql.test_package.test_uppercase('xxx') # => 'XXX' plsql.hr.test_package.test_uppercase('xxx') # => 'XXX' plsql.logoff
  23. 23. 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 )[:p_employee_id] PL/SQL end set_update_method do procedūras plsql.employees_pkg.update_employee( esošās :p_employee_id => id, :p_first_name => first_name, datubāzēs :p_last_name => last_name ) end set_delete_method do plsql.employees_pkg.delete_employee( :p_employee_id => id ) end end
  24. 24. Paldies! http://blog.rayapps.com http://github.com/rsim

×