Module: DataMapper::Constraints::Adapters::OracleAdapter

Includes:
DataObjectsAdapter
Defined in:
lib/data_mapper/constraints/adapters/oracle_adapter.rb

Instance Method Summary collapse

Methods included from DataObjectsAdapter

#create_relationship_constraint, #destroy_relationship_constraint

Instance Method Details

#constraint_exists?(storage_name, constraint_name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

oracle does not provide the information_schema table To question internal state like postgres or mysql

Returns:

  • (Boolean)

See Also:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/data_mapper/constraints/adapters/oracle_adapter.rb', line 16

def constraint_exists?(storage_name, constraint_name)
  statement = DataMapper::Ext::String.compress_lines("    SELECT COUNT(*)\n    FROM USER_CONSTRAINTS\n    WHERE table_name = ?\n    AND constraint_name = ?\n  SQL\n\n  select(statement, oracle_upcase(storage_name)[0, self.class::IDENTIFIER_MAX_LENGTH].gsub('\"', '_'), oracle_upcase(constraint_name)[0, self.class::IDENTIFIER_MAX_LENGTH].gsub('\"', '_')).first > 0\n\nend\n")

#create_constraints_statement(constraint_name, constraint_type, source_storage_name, source_keys, target_storage_name, target_keys) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: is it desirable to always set ‘INITIALLY DEFERRED DEFERRABLE`?

See Also:

  • DataObjectsAdapter#create_constraints_statement


34
35
36
37
38
39
40
41
42
43
# File 'lib/data_mapper/constraints/adapters/oracle_adapter.rb', line 34

def create_constraints_statement(constraint_name, constraint_type, source_storage_name, source_keys, target_storage_name, target_keys)
  DataMapper::Ext::String.compress_lines("    ALTER TABLE \#{quote_name(source_storage_name)}\n    ADD CONSTRAINT \#{quote_name(constraint_name)}\n    FOREIGN KEY (\#{source_keys.join(', ')})\n    REFERENCES \#{quote_name(target_storage_name)} (\#{target_keys.join(', ')})\n    \#{\"ON DELETE \" + constraint_type if constraint_type && constraint_type != \"NO ACTION\"}\n    INITIALLY DEFERRED DEFERRABLE\n  SQL\nend\n")

#destroy_constraints_statement(storage_name, constraint_name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
49
50
51
52
# File 'lib/data_mapper/constraints/adapters/oracle_adapter.rb', line 46

def destroy_constraints_statement(storage_name, constraint_name)
  DataMapper::Ext::String.compress_lines("    ALTER TABLE \#{quote_name(storage_name)}\n    DROP CONSTRAINT \#{quote_name(constraint_name)}\n    CASCADE\n  SQL\nend\n")