Module: DataMapper::Migrations::OracleAdapter

### Home Classes Methods

### In Files

- lib/dm-migrations/adapters/dm-oracle-adapter.rb

### Namespace

- MODULE DataMapper::Migrations::OracleAdapter::ClassMethods

### Methods

- ::included
- #create_model_storage
- #destroy_model_storage
- #drop_table_statement
- #field_exists?
- #sequence_exists?
- #storage_exists?
- #storage_fields

### Included Modules

- DataMapper::Migrations::DataObjectsAdapter

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Migration
- DataMapper::MigrationRunner
- DataMapper::Migrations
- DataMapper::Migrations::DataObjectsAdapter
- DataMapper::Migrations::DataObjectsAdapter::ClassMethods
- DataMapper::Migrations::DuplicateMigration
- DataMapper::Migrations::Model
- DataMapper::Migrations::MysqlAdapter
- DataMapper::Migrations::MysqlAdapter::ClassMethods
- DataMapper::Migrations::OracleAdapter
- DataMapper::Migrations::OracleAdapter::ClassMethods
- DataMapper::Migrations::PostgresAdapter
- DataMapper::Migrations::PostgresAdapter::ClassMethods
- DataMapper::Migrations::Repository
- DataMapper::Migrations::SingletonMethods
- DataMapper::Migrations::SqliteAdapter
- DataMapper::Migrations::SqliteAdapter::ClassMethods
- DataMapper::Migrations::SqlserverAdapter
- DataMapper::Migrations::SqlserverAdapter::ClassMethods
- DataMapper::Migrations::YamlAdapter
- SQL
- SQL::Column
- SQL::Mysql
- SQL::Mysql::Column
- SQL::Mysql::Table
- SQL::Postgres
- SQL::Postgres::Column
- SQL::Postgres::Table
- SQL::Sqlite
- SQL::Sqlite::Column
- SQL::Sqlite::Table
- SQL::Table
- SQL::TableCreator
- SQL::TableCreator::Column
- SQL::TableCreator::SqlExpr
- SQL::TableModifier
- Spec
- Spec::Example
- Spec::Example::MigrationExampleGroup
- Spec::Matchers
- Spec::Matchers::Migration
- Spec::Matchers::Migration::HaveColumnMatcher
- Spec::Matchers::Migration::HaveTableMatcher
- Spec::Matchers::Migration::NullableColumnMatcher
- Spec::Matchers::Migration::PrimaryKeyMatcher
- Object

No matching classes.

# DataMapper::Migrations::OracleAdapter

### Public Class Methods

included(base) click to toggle source

@api private

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 11
    def self.included(base)
      base.extend DataObjectsAdapter::ClassMethods
      base.extend ClassMethods
    end

### Public Instance Methods

create_model_storage(model) click to toggle source

@api semipublic

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 73
    def create_model_storage(model)
      name       = self.name
      properties = model.properties_with_subclasses(name)
      table_name = model.storage_name(name)
      truncate_or_delete = self.class.auto_migrate_with
      table_is_truncated = truncate_or_delete && @truncated_tables && @truncated_tables[table_name]

      return false if storage_exists?(table_name) && !table_is_truncated
      return false if properties.empty?

      with_connection do |connection|
        # if table was truncated then check if all columns for properties are present
        # TODO: check all other column definition options
        if table_is_truncated && storage_has_all_fields?(table_name, properties)
          @truncated_tables[table_name] = nil
        else
          # forced drop of table if properties are different
          if truncate_or_delete
            destroy_model_storage(model, true)
          end

          statements = [ create_table_statement(connection, model, properties) ]
          statements.concat(create_index_statements(model))
          statements.concat(create_unique_index_statements(model))
          statements.concat(create_sequence_statements(model))

          statements.each do |statement|
            command   = connection.create_command(statement)
            command.execute_non_query
          end
        end

      end

      true
    end

destroy_model_storage(model, forced = false) click to toggle source

@api semipublic

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 111
    def destroy_model_storage(model, forced = false)
      table_name = model.storage_name(name)
      klass      = self.class
      truncate_or_delete = klass.auto_migrate_with
      if storage_exists?(table_name)
        if truncate_or_delete && !forced
          case truncate_or_delete
          when :truncate
            execute(truncate_table_statement(model))
          when :delete
            execute(delete_table_statement(model))
          else
            raise ArgumentError, "Unsupported auto_migrate_with option"
          end
          @truncated_tables ||= {}
          @truncated_tables[table_name] = true
        else
          execute(drop_table_statement(model))
          @truncated_tables[table_name] = nil if @truncated_tables
        end
      end
      # added destroy of sequences
      reset_sequences = klass.auto_migrate_reset_sequences
      table_is_truncated = @truncated_tables && @truncated_tables[table_name]
      unless truncate_or_delete && !reset_sequences && !forced
        if sequence_exists?(model_sequence_name(model))
          statement = if table_is_truncated && !forced
            reset_sequence_statement(model)
          else
            drop_sequence_statement(model)
          end
          execute(statement) if statement
        end
      end
      true
    end

drop_table_statement(model) click to toggle source

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 66
    def drop_table_statement(model)
      table_name = quote_name(model.storage_name(name))
      "DROP TABLE #{table_name} CASCADE CONSTRAINTS"
    end

field_exists?(storage_name, field_name) click to toggle source

@api semipublic

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 42
    def field_exists?(storage_name, field_name)
      statement = DataMapper::Ext::String.compress_lines(          SELECT COUNT(*)          FROM all_tab_columns          WHERE owner = ?          AND table_name = ?          AND column_name = ?)

      select(statement, schema_name, oracle_upcase(storage_name), oracle_upcase(field_name)).first > 0
    end

sequence_exists?(sequence_name) click to toggle source

@api semipublic

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 29
    def sequence_exists?(sequence_name)
      return false unless sequence_name
      statement = DataMapper::Ext::String.compress_lines(          SELECT COUNT(*)          FROM all_sequences          WHERE sequence_owner = ?          AND sequence_name = ?)

      select(statement, schema_name, oracle_upcase(sequence_name)).first > 0
    end

storage_exists?(storage_name) click to toggle source

@api semipublic

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 17
    def storage_exists?(storage_name)
      statement = DataMapper::Ext::String.compress_lines(          SELECT COUNT(*)          FROM all_tables          WHERE owner = ?          AND table_name = ?)

      select(statement, schema_name, oracle_upcase(storage_name)).first > 0
    end

storage_fields(storage_name) click to toggle source

@api semipublic

    # File lib/dm-migrations/adapters/dm-oracle-adapter.rb, line 55
    def storage_fields(storage_name)
      statement = DataMapper::Ext::String.compress_lines(          SELECT column_name          FROM all_tab_columns          WHERE owner = ?          AND table_name = ?)

      select(statement, schema_name, oracle_upcase(storage_name))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.