Class: SimpleOracleJDBC::Interface
- Inherits:
-
Object
- Object
- SimpleOracleJDBC::Interface
- Defined in:
- lib/simple_oracle_jdbc/interface.rb
Instance Attribute Summary collapse
-
#connection ⇒ JDBC Oracle Database connection
Returns the raw JDBC database connection.
Class Method Summary collapse
-
.create(user, password, database_service, host = nil, port = nil) ⇒ Object
Factory method to establish a new JDBC connection and create a new interface.
-
.create_with_existing_connection(conn) ⇒ Object
Factory method to create a new interface using an existing database connection.
Instance Method Summary collapse
-
#commit ⇒ Object
Performs a commit on the database connection.
-
#connect(user, password, database_service, host = nil, port = nil) ⇒ Object
Establishes a new database connection using the supplied parameters.
-
#disconnect ⇒ Object
Closes the database connection.
-
#execute_proc(sql, *binds) ⇒ Object
(also: #execute_call)
Executes a stored procedure call using the DBCall class.
-
#execute_sql(query, *binds) ⇒ Object
Executes a SQL statement using the Sql class.
-
#prepare_proc(sql) ⇒ Object
(also: #prepare_call)
Prepares a stored procedure call using the DBCall class.
-
#prepare_sql(query) ⇒ Object
Prepares a SQL statement using the Sql class.
-
#rollback ⇒ Object
Performs a rollback on the database connection.
Instance Attribute Details
#connection ⇒ JDBC Oracle Database connection
Returns the raw JDBC database connection
29 30 31 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 29 def connection @connection end |
Class Method Details
.create(user, password, database_service, host = nil, port = nil) ⇒ Object
Factory method to establish a new JDBC connection and create a new interface. Returns a SimpleOracleJDBC::Interface
41 42 43 44 45 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 41 def self.create(user, password, database_service, host=nil, port=nil) conn = self.new conn.connect(user, password, database_service, host, port) conn end |
.create_with_existing_connection(conn) ⇒ Object
Factory method to create a new interface using an existing database connection. Returns an instance of SimpleOracleJDBC::Interface
33 34 35 36 37 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 33 def self.create_with_existing_connection(conn) connector = self.new connector.set_connection conn connector end |
Instance Method Details
#commit ⇒ Object
Performs a commit on the database connection
65 66 67 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 65 def commit @connection.commit end |
#connect(user, password, database_service, host = nil, port = nil) ⇒ Object
Establishes a new database connection using the supplied parameters.
48 49 50 51 52 53 54 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 48 def connect(user, password, database_service, host=nil, port=nil) oradriver = OracleDriver.new DriverManager.registerDriver oradriver @connection = DriverManager.get_connection "jdbc:oracle:thin:@#{host}:#{port}/#{database_service}", user, password @connection.auto_commit = false end |
#disconnect ⇒ Object
Closes the database connection
57 58 59 60 61 62 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 57 def disconnect if @connection @connection.close @connection = nil end end |
#execute_proc(sql, *binds) ⇒ Object Also known as: execute_call
Executes a stored procedure call using the DBCall class.
Returns a DBCall object
100 101 102 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 100 def execute_proc(sql, *binds) DBCall.execute(@connection, sql, *binds) end |
#execute_sql(query, *binds) ⇒ Object
Executes a SQL statement using the Sql class
Returns a Sql object
84 85 86 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 84 def execute_sql(query, *binds) Sql.execute(@connection, query, *binds) end |
#prepare_proc(sql) ⇒ Object Also known as: prepare_call
Prepares a stored procedure call using the DBCall class.
Returns a DBCall object
91 92 93 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 91 def prepare_proc(sql) DBCall.prepare(@connection, sql) end |
#prepare_sql(query) ⇒ Object
Prepares a SQL statement using the Sql class.
Returns a Sql object.
77 78 79 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 77 def prepare_sql(query) Sql.prepare(@connection, query) end |
#rollback ⇒ Object
Performs a rollback on the database connection
70 71 72 |
# File 'lib/simple_oracle_jdbc/interface.rb', line 70 def rollback @connection.rollback end |