Class: JRubySQL::RDBMS
- Inherits:
-
Object
- Object
- JRubySQL::RDBMS
- Includes:
- Messages
- Defined in:
- lib/jrubysql/rdbms.rb
Class Method Summary collapse
Instance Method Summary collapse
- #autocommit ⇒ Object
- #autocommit=(ac) ⇒ Object
- #close ⇒ Object
- #execute(sql) ⇒ Object
-
#initialize(options) ⇒ RDBMS
constructor
A new instance of RDBMS.
Methods included from Messages
Constructor Details
#initialize(options) ⇒ RDBMS
Returns a new instance of RDBMS.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jrubysql/rdbms.rb', line 26 def initialize @conn = if [:type] case [:type] when :mysql JDBCHelper::MySQL.connect( [:host], [:user], [:password], [:database]) when :oracle host, svc = [:host].split('/') if svc.nil? # FIXME raise ArgumentError.new m(:oracle_service_name_required) end JDBCHelper::Oracle.connect( host, [:user], [:password], svc) when :postgres JDBCHelper::Postgres.connect( [:host], [:user], [:password], [:database]) when :sqlserver JDBCHelper::SqlServer.connect( [:host], [:user], [:password], [:database]) when :cassandra JDBCHelper::Cassandra.connect( [:host], [:database]) when :sqlite JDBCHelper::Connection.new( { :driver => 'org.sqlite.JDBC', :url => "jdbc:sqlite:#{[:host]}", :user => [:user], :password => [:password] }.reject { |k, v| v.nil? } ) end elsif [:driver] JDBCHelper::Connection.new( { :driver => [:driver], :url => [:url], :user => [:user], :password => [:password] }.reject { |k, v| v.nil? } ) else raise ArgumentError.new m(:invalid_connection) end end |
Class Method Details
.get_type(driver_or_type) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jrubysql/rdbms.rb', line 7 def self.get_type driver_or_type case driver_or_type.to_s.downcase when /oracle/ :oracle when /mysql/ :mysql when /postgres/ :postgres when /sqlserver/ :sqlserver when /sqlite/ :sqlite when /cassandra/ :cassandra else :unknown end end |
Instance Method Details
#autocommit ⇒ Object
74 75 76 |
# File 'lib/jrubysql/rdbms.rb', line 74 def autocommit @conn.java_obj.get_auto_commit end |
#autocommit=(ac) ⇒ Object
78 79 80 |
# File 'lib/jrubysql/rdbms.rb', line 78 def autocommit= ac @conn.java_obj.set_auto_commit ac end |
#close ⇒ Object
82 83 84 |
# File 'lib/jrubysql/rdbms.rb', line 82 def close @conn.close end |
#execute(sql) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jrubysql/rdbms.rb', line 86 def execute sql st = Time.now result = @conn.execute sql elapsed = Time.now - st { :set? => result.respond_to?(:each), :result => result, :elapsed => elapsed } end |