Wednesday, April 9, 2008

ActiveRecord-JDBC-Adapter Code Hacking

Activerecord-JDBC-Adapter RDoc : http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter/

SVN: http://jruby-extras.rubyforge.org/svn/trunk/activerecord-jdbc/

Project Home Page

 

1.  lib/active_record/connection_adapters/jdbc_adapter.rb

Class
ActiveRecord::ConnectionAdapters::JdbcDriver  < Object

  • load and initialize JDBC Drivers

Methods

connection create driver_class load new

 

 Class
ActiveRecord::ConnectionAdapters::JdbcColumn < Column

  • defines column type conversion,  default value etc. For subclass to override.

Methods

default_value init_column new simplified_type type_cast_code

 

Class
ActiveRecord::ConnectionAdapters::JdbcAdapter < AbstractAdapter

  • extends AbstractAdapter, defines basic DML functions
  • needs to be sub-classed for specific DBs.

Methods

_execute begin_db_transaction commit_db_transaction disconnect! execute indexes jdbc_columns jdbc_insert jdbc_select_all modify_types native_sql_to_type new reconnect! rollback_db_transaction select_one select_rows supports_migrations? tables write_large_object

 

2. lib/jdbc_adapter/jdbc_oracle.rb

Module
::JdbcSpec::Oracle

  • defines Oracle specific DDL and DML functions by calling self-defined Java class in JdbcAdapterInternalService.java which wraps generic JDBC DML/DDL operations.
  • extends ActiveRecord::ConnectionAdapters::JdbcAdapter through adapter_selector() and ADAPTER_TYPES.
Methods

_execute adapter_selector add_order_by_for_association_limiting! column_selector distinct indexes modify_types recreate_database table_alias_length

 

Module
::JdbcSpec::Oracle::Column

  • extends ActiveRecord::ConnectionAdapters::JdbcColumn through column_selector() and COLUMN_TYPES.
  • defines data type conversion between Oracle and Ruby by overriding methods (type_cast and type_cast_code) in Column class.

No comments:

 
free hit counter
hit counter