module ArJdbc
this file is discovered by the extension mechanism @see {ArJdbc#discover_extensions}
Copyright © 2008-2015
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Constants
- AR40
@private
- AR42
@private
- AR50
@private
- ConnectionMethods
- FireBird
- MissingFunctionalityHelper
@private @deprecated backwards compatibility
- MsSQL
- SerializedAttributesHelper
@private only due backwards compatibility
- VERSION
Public Class Methods
# File lib/arjdbc/jdbc.rb, line 33 def deprecate(message, once = nil) # adds a "DEPRECATION WARNING: " prefix ::ActiveSupport::Deprecation.warn(message, caller_locations) || true if warn?(message, once) end
Defines an AR-JDBC extension. An extension consists of a declaration using this method and an ArJdbc::XYZ module that contains implementation and overrides for methods in ActiveRecord::ConnectionAdapters::AbstractAdapter. When you declare your extension, you provide a block that detects when a database configured to use the extension is present and loads the necessary code for it. AR-JDBC will patch the code into the base JdbcAdapter by extending an instance of it with your extension module.
name
the name of a module to be defined under the ArJdbc
module.
block
should be a one- or two-arity block that receives the dialect name or driver class name as the first argument, and optionally the whole database configuration hash as a second argument
Example:
ArJdbc.extension :FRoB do |name| if name =~ /frob/i require 'arjdbc/frob' # contains ArJdbc::FRoB true end end
# File lib/arjdbc/jdbc/extension.rb, line 26 def self.extension(name, &block) if const_defined?(name) mod = const_get(name) else mod = const_set(name, Module.new) end (class << mod; self; end).instance_eval do define_method :adapter_matcher do |_name, config| if block.arity == 1 block.call(_name) ? mod : false else block.call(_name, config) ? mod : false end end end unless mod.respond_to?(:adapter_matcher) end
# File lib/arjdbc/jdbc.rb, line 29 def warn(message, once = nil) super(message) || true if warn?(message, once) end
@private Internal API
# File lib/arjdbc/jdbc.rb, line 15 def warn_unsupported_adapter(adapter, version = nil) warn_prefix = 'NOTE:' if version # e.g. [4, 2] ar_version = [ ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR, ActiveRecord::VERSION::TINY ] if ( ar_version <=> version ) >= 0 # e.g. 4.2.0 > 4.2 warn_prefix = "NOTE: ActiveRecord #{version.join('.')} with" else warn_prefix = nil end end warn "#{warn_prefix} adapter: #{adapter} is not (yet) fully supported by AR-JDBC," << " please consider helping us out." if warn_prefix end
Private Class Methods
# File lib/arjdbc/jdbc/extension.rb, line 44 def self.discover_extensions if defined?(Gem) && Gem.respond_to?(:find_files) files = Gem.find_files('arjdbc/discover') else files = $LOAD_PATH.map do |path| discover = File.join(path, 'arjdbc', 'discover.rb') File.exist?(discover) ? discover : nil end.compact end files.each do |file| puts "Loading AR-JDBC extension #{file}" if $DEBUG require file end end
# File lib/arjdbc/jdbc.rb, line 42 def warn?(message, once) return nil if @@warns.equal?(false) || ! message warns = @@warns ||= ( require 'set'; Set.new ) return false if warns.include?(message) warns << message.dup if once true end
Public Instance Methods
# File lib/arjdbc/jdbc/connection_methods.rb, line 23 def embedded_driver(config) config[:username] ||= "sa" config[:password] ||= "" jdbc_connection(config) end
# File lib/arjdbc/jdbc/connection_methods.rb, line 9 def jdbc_connection(config) adapter_class = config[:adapter_class] adapter_class ||= ::ActiveRecord::ConnectionAdapters::JdbcAdapter # Once all adapters converted to AR5 then this rescue can be removed begin adapter_class.new(nil, logger, nil, config) rescue ArgumentError adapter_class.new(nil, logger, config) end end
# File lib/arjdbc/jdbc/connection_methods.rb, line 31 def jndi_config?(config) ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config) end
# File lib/arjdbc/jdbc/connection_methods.rb, line 21 def jndi_connection(config); jdbc_connection(config) end
# File lib/arjdbc/derby/schema_creation.rb, line 11 def schema_creation SchemaCreation.new self end