Class: DataObjects::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Connection

Returns a new instance of Connection.

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb', line 79

def initialize(uri)
  raise NotImplementedError.new
end

Class Method Details

.inherited(target) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb', line 43

def self.inherited(target)
  target.class_eval do

    def self.new(*args)
      instance = allocate
      instance.send(:initialize, *args)
      instance
    end

    include Extlib::Pooling
    alias close release
  end

  if driver_module_name = target.name.split('::')[-2]
    driver_module = DataObjects::const_get(driver_module_name)
    driver_module.class_eval <<-EOS, __FILE__, __LINE__
      def self.logger
        @logger
      end

      def self.logger=(logger)
        @logger = logger
      end
    EOS

    driver_module.logger = DataObjects::Logger.new(nil, :off)
  end
end

.new(uri_s) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb', line 11

def self.new(uri_s)
  uri = DataObjects::URI::parse(uri_s)

  case uri.scheme.to_sym
  when :java
    warn 'JNDI URLs (connection strings) are only for use with JRuby' unless RUBY_PLATFORM =~ /java/
    # TODO: handle jndi connection strings
  when :jdbc
    warn 'JDBC URLs (connection strings) are only for use with JRuby' unless RUBY_PLATFORM =~ /java/

    driver_name = if uri.path.split(':').first == 'sqlite'
      'sqlite3'
    elsif uri.path.split(':').first == 'postgresql'
      'postgres'
    else
      uri.path.split(':').first
    end

    conn_uri = uri_s # NOTE: for now, do not reformat this JDBC connection
                     # string -- or, in other words, do not let
                     # DataObjects::URI#to_s be called -- as it is not
                     # correctly handling JDBC URLs, and in doing so, causing
                     # java.sql.DriverManager.getConnection to throw a
                     # 'No suitable driver found for...' exception.
  else
    driver_name = uri.scheme
    conn_uri = uri
  end

  DataObjects.const_get(driver_name.capitalize)::Connection.new(conn_uri)
end

Instance Method Details

#create_command(text) ⇒ Object



87
88
89
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb', line 87

def create_command(text)
  concrete_command.new(self, text)
end

#disposeObject

Raises:

  • (NotImplementedError)


83
84
85
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb', line 83

def dispose
  raise NotImplementedError.new
end

#to_sObject

Standard API Definition



75
76
77
# File 'lib/gems/data_objects-0.9.10.1/lib/data_objects/connection.rb', line 75

def to_s
  @uri.to_s
end