From 632808aca86aea202652b5d82ffab7f0c75839c7 Mon Sep 17 00:00:00 2001 From: Raimonds Simanovskis Date: Wed, 24 Feb 2010 14:07:51 +0200 Subject: [PATCH] updated History and RDoc comments --- History.txt | 2 + .../oracle_enhanced_adapter.rb | 38 +++++++++++-------- .../oracle_enhanced_procedures.rb | 6 +-- .../oracle_enhanced_schema_definitions.rb | 2 +- .../oracle_enhanced_schema_dumper.rb | 2 +- .../oracle_enhanced_adapter_spec.rb | 2 +- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/History.txt b/History.txt index 34b2942e0..d75533018 100644 --- a/History.txt +++ b/History.txt @@ -1,6 +1,8 @@ == 1.2.4 2010-02-23 * Enhancements: + * rake db:test:purge will drop all schema objects from test schema (including views, synonyms, packages, functions, procedures) - + they should be always reloaded before tests run if necessary * added views, synonyms, packages, functions, procedures, indexes, triggers, types, primary, unique and foreign key constraints to structure dump * added :temporary option for create_table to create temporary tables * added :tablespace option for add_index diff --git a/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb b/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb index 1cd0ffcbe..e01b07db6 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb @@ -419,6 +419,7 @@ def supports_savepoints? #:nodoc: true end + #:stopdoc: NATIVE_DATABASE_TYPES = { :primary_key => "NUMBER(38) NOT NULL PRIMARY KEY", :string => { :name => "VARCHAR2", :limit => 255 }, @@ -439,6 +440,7 @@ def supports_savepoints? #:nodoc: NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS = NATIVE_DATABASE_TYPES.dup.merge( :boolean => { :name => "VARCHAR2", :limit => 1 } ) + #:startdoc: def native_database_types #:nodoc: emulate_booleans_from_strings ? NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS : NATIVE_DATABASE_TYPES @@ -606,7 +608,8 @@ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) # end protected :insert_sql - AUTOGENERATED_SEQUENCE_NAME = 'autogenerated'.freeze #:nodoc: + # use in set_sequence_name to avoid fetching primary key value from sequence + AUTOGENERATED_SEQUENCE_NAME = 'autogenerated'.freeze # Returns the next sequence value from a sequence generator. Not generally # called directly; used by ActiveRecord to get the next primary key value @@ -736,16 +739,17 @@ def lob_order_by_expression(klass, order) #:nodoc: # # see: abstract/schema_statements.rb - # current database name + # Current database name def current_database select_value("select sys_context('userenv','db_name') from dual") end - # current database session user + # Current database session user def current_user select_value("select sys_context('userenv','session_user') from dual") end + # Default tablespace name of current user def default_tablespace select_value("select lower(default_tablespace) from user_users where username = sys_context('userenv','session_user')") end @@ -1205,7 +1209,7 @@ def structure_dump #:nodoc: select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') order by 1").inject(s) do |structure, table| table_name = table['table_name'] virtual_columns = virtual_columns_for(table_name) - ddl = "create#{ ' global temporary' if temporary?(table_name)} table #{table_name} (\n " + ddl = "create#{ ' global temporary' if temporary_table?(table_name)} table #{table_name} (\n " cols = select_all(%Q{ select column_name, data_type, data_length, char_used, char_length, data_precision, data_scale, data_default, nullable from user_tab_columns @@ -1226,7 +1230,7 @@ def structure_dump #:nodoc: end end - def structure_dump_virtual_column(column, data_default) + def structure_dump_virtual_column(column, data_default) #:nodoc: data_default = data_default.gsub(/"/, '') col = "#{column['column_name'].downcase} #{column['data_type'].downcase}" if column['data_type'] =='NUMBER' and !column['data_precision'].nil? @@ -1240,7 +1244,7 @@ def structure_dump_virtual_column(column, data_default) col << " GENERATED ALWAYS AS (#{data_default}) VIRTUAL" end - def structure_dump_column(column) + def structure_dump_column(column) #:nodoc: col = "#{column['column_name'].downcase} #{column['data_type'].downcase}" if column['data_type'] =='NUMBER' and !column['data_precision'].nil? col << "(#{column['data_precision'].to_i}" @@ -1255,12 +1259,12 @@ def structure_dump_column(column) col end - def structure_dump_constraints(table) + def structure_dump_constraints(table) #:nodoc: out = [structure_dump_primary_key(table), structure_dump_unique_keys(table)].flatten.compact out.length > 0 ? ",\n#{out.join(",\n")}" : '' end - def structure_dump_primary_key(table) + def structure_dump_primary_key(table) #:nodoc: opts = {:name => '', :cols => []} pks = select_all(<<-SQL, "Primary Keys") select a.constraint_name, a.column_name, a.position @@ -1278,7 +1282,7 @@ def structure_dump_primary_key(table) opts[:cols].length > 0 ? " CONSTRAINT #{opts[:name]} PRIMARY KEY (#{opts[:cols].join(',')})" : nil end - def structure_dump_unique_keys(table) + def structure_dump_unique_keys(table) #:nodoc: keys = {} uks = select_all(<<-SQL, "Primary Keys") select a.constraint_name, a.column_name, a.position @@ -1298,7 +1302,7 @@ def structure_dump_unique_keys(table) end end - def structure_dump_fk_constraints + def structure_dump_fk_constraints #:nodoc: fks = select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') order by 1").map do |table| if respond_to?(:foreign_keys) && (foreign_keys = foreign_keys(table["table_name"])).any? foreign_keys.map do |fk| @@ -1353,7 +1357,7 @@ def structure_dump_db_stored_code #:nodoc: structure end - def structure_dump_indexes(table_name) + def structure_dump_indexes(table_name) #:nodoc: statements = indexes(table_name).map do |options| #def add_index(table_name, column_name, options = {}) column_names = options[:columns] @@ -1382,14 +1386,14 @@ def structure_drop #:nodoc: end end - def temp_table_drop + def temp_table_drop #:nodoc: # changed select from user_tables to all_tables - much faster in large data dictionaries select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') and temporary = 'Y' order by 1").inject('') do |drop, table| drop << "drop table #{table.to_a.first.last} cascade constraints;\n\n" end end - def full_drop(preserve_tables=false) + def full_drop(preserve_tables=false) #:nodoc: s = preserve_tables ? [] : [structure_drop] s << temp_table_drop if preserve_tables s << drop_sql_for_feature("view") @@ -1444,10 +1448,11 @@ def distinct(columns, order_by) #:nodoc: sql << order_columns * ", " end - def temporary?(table_name) + def temporary_table?(table_name) #:nodoc: select_value("select temporary from user_tables where table_name = '#{table_name.upcase}'") == 'Y' end + # statements separator used in structure dump STATEMENT_TOKEN = "\n\n--@@@--\n\n" # ORDER BY clause for the passed order option. @@ -1560,7 +1565,10 @@ def drop_sql_for_object(type) # PL/SQL in Oracle uses dbms_output for logging print statements # These methods stick that output into the Rails log so Ruby and PL/SQL # code can can be debugged together in a single application - DBMS_OUTPUT_BUFFER_SIZE = 10000 #can be 1-1000000 + + # Maximum DBMS_OUTPUT buffer size + DBMS_OUTPUT_BUFFER_SIZE = 10000 # can be 1-1000000 + # Turn DBMS_Output logging on def enable_dbms_output set_dbms_output_plsql_connection diff --git a/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb b/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb index e3ae72334..95292efd3 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb @@ -52,7 +52,7 @@ def set_delete_method(&block) self.custom_delete_method = block end - def create_method_name_before_custom_methods + def create_method_name_before_custom_methods #:nodoc: if private_method_defined?(:create_without_timestamps) && defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::STRING.to_f >= 2.3 :create_without_timestamps elsif private_method_defined?(:create_without_callbacks) @@ -62,7 +62,7 @@ def create_method_name_before_custom_methods end end - def update_method_name_before_custom_methods + def update_method_name_before_custom_methods #:nodoc: if private_method_defined?(:update_without_dirty) :update_without_dirty elsif private_method_defined?(:update_without_timestamps) && defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::STRING.to_f >= 2.3 @@ -74,7 +74,7 @@ def update_method_name_before_custom_methods end end - def destroy_method_name_before_custom_methods + def destroy_method_name_before_custom_methods #:nodoc: if public_method_defined?(:destroy_without_callbacks) :destroy_without_callbacks else diff --git a/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb b/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb index 705cd0a8f..e75a0cd12 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb @@ -6,7 +6,7 @@ class OracleEnhancedForeignKeyDefinition < Struct.new(:from_table, :to_table, :o class OracleEnhancedSynonymDefinition < Struct.new(:name, :table_owner, :table_name, :db_link) #:nodoc: end - class OracleEnhancedIndexDefinition < Struct.new(:table, :name, :unique, :tablespace, :columns) + class OracleEnhancedIndexDefinition < Struct.new(:table, :name, :unique, :tablespace, :columns) #:nodoc: end module OracleEnhancedSchemaDefinitions #:nodoc: diff --git a/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb b/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb index 69bc49bc8..a2bd9bef8 100644 --- a/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +++ b/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb @@ -119,7 +119,7 @@ def oracle_enhanced_table(table, stream) tbl.print " create_table #{table.inspect}" # addition to make temporary option work - tbl.print ", :temporary => true" if @connection.temporary?(table) + tbl.print ", :temporary => true" if @connection.temporary_table?(table) if columns.detect { |c| c.name == pk } if pk != 'id' diff --git a/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb b/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb index a2df05b67..e6a29057c 100644 --- a/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +++ b/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb @@ -471,7 +471,7 @@ class ::TestPost < ActiveRecord::Base @conn.create_table :foos, :temporary => true, :id => false do |t| t.integer :id end - @conn.temporary?("foos").should be_true + @conn.temporary_table?("foos").should be_true end end end