activerecord-jdbc-adapter 5.0.pre1 → 51.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.travis.yml +15 -416
  4. data/Gemfile +35 -37
  5. data/README.md +23 -118
  6. data/RUNNING_TESTS.md +31 -26
  7. data/Rakefile +2 -3
  8. data/activerecord-jdbc-adapter.gemspec +1 -2
  9. data/lib/arjdbc/abstract/connection_management.rb +21 -0
  10. data/lib/arjdbc/abstract/core.rb +62 -0
  11. data/lib/arjdbc/abstract/database_statements.rb +46 -0
  12. data/lib/arjdbc/abstract/statement_cache.rb +58 -0
  13. data/lib/arjdbc/abstract/transaction_support.rb +86 -0
  14. data/lib/arjdbc/derby/adapter.rb +6 -1
  15. data/lib/arjdbc/discover.rb +0 -7
  16. data/lib/arjdbc/firebird/adapter.rb +2 -2
  17. data/lib/arjdbc/jdbc/adapter.rb +10 -252
  18. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  19. data/lib/arjdbc/jdbc/connection.rb +6 -0
  20. data/lib/arjdbc/jdbc.rb +2 -2
  21. data/lib/arjdbc/mysql/adapter.rb +87 -944
  22. data/lib/arjdbc/mysql/connection_methods.rb +4 -2
  23. data/lib/arjdbc/postgresql/adapter.rb +288 -1023
  24. data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
  25. data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
  26. data/lib/arjdbc/postgresql/base/pgconn.rb +8 -5
  27. data/lib/arjdbc/postgresql/column.rb +10 -599
  28. data/lib/arjdbc/postgresql/connection_methods.rb +9 -0
  29. data/lib/arjdbc/postgresql/name.rb +24 -0
  30. data/lib/arjdbc/postgresql/oid_types.rb +25 -110
  31. data/lib/arjdbc/sqlite3/adapter.rb +171 -170
  32. data/lib/arjdbc/tasks/database_tasks.rb +1 -3
  33. data/lib/arjdbc/tasks/db2_database_tasks.rb +2 -2
  34. data/lib/arjdbc/version.rb +1 -1
  35. data/pom.xml +3 -3
  36. data/rakelib/02-test.rake +0 -12
  37. data/rakelib/compile.rake +1 -1
  38. data/rakelib/db.rake +7 -5
  39. data/rakelib/rails.rake +63 -64
  40. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +1 -17
  41. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +518 -1260
  42. data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
  43. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +53 -134
  44. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -240
  45. data/src/java/arjdbc/sqlite3/SQLite3Module.java +0 -20
  46. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +85 -10
  47. metadata +20 -34
  48. data/Appraisals +0 -41
  49. data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
  50. data/lib/arjdbc/common_jdbc_methods.rb +0 -89
  51. data/lib/arjdbc/mysql/bulk_change_table.rb +0 -150
  52. data/lib/arjdbc/mysql/column.rb +0 -162
  53. data/lib/arjdbc/mysql/explain_support.rb +0 -82
  54. data/lib/arjdbc/mysql/schema_creation.rb +0 -58
  55. data/lib/arjdbc/oracle/adapter.rb +0 -952
  56. data/lib/arjdbc/oracle/column.rb +0 -126
  57. data/lib/arjdbc/oracle/connection_methods.rb +0 -21
  58. data/lib/arjdbc/oracle.rb +0 -4
  59. data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +0 -21
  60. data/lib/arjdbc/postgresql/base/oid.rb +0 -412
  61. data/lib/arjdbc/postgresql/base/schema_definitions.rb +0 -131
  62. data/lib/arjdbc/postgresql/explain_support.rb +0 -53
  63. data/lib/arjdbc/postgresql/oid/bytea.rb +0 -2
  64. data/lib/arjdbc/postgresql/schema_creation.rb +0 -60
  65. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +0 -297
  66. data/lib/arjdbc/tasks/oracle_database_tasks.rb +0 -65
  67. data/src/java/arjdbc/oracle/OracleModule.java +0 -75
  68. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +0 -465
@@ -11,6 +11,10 @@ require 'arjdbc/jdbc/connection'
11
11
  require 'arjdbc/jdbc/callbacks'
12
12
  require 'arjdbc/jdbc/extension'
13
13
  require 'arjdbc/jdbc/type_converter'
14
+ require 'arjdbc/abstract/core'
15
+ require 'arjdbc/abstract/connection_management'
16
+ require 'arjdbc/abstract/database_statements'
17
+ require 'arjdbc/abstract/transaction_support'
14
18
 
15
19
  module ActiveRecord
16
20
  module ConnectionAdapters
@@ -34,7 +38,12 @@ module ActiveRecord
34
38
  class JdbcAdapter < AbstractAdapter
35
39
  include Jdbc::ConnectionPoolCallbacks
36
40
 
37
- attr_reader :config, :prepared_statements
41
+ include ArJdbc::Abstract::Core
42
+ include ArJdbc::Abstract::ConnectionManagement
43
+ include ArJdbc::Abstract::DatabaseStatements
44
+ include ArJdbc::Abstract::TransactionSupport
45
+
46
+ attr_reader :prepared_statements
38
47
 
39
48
  def self.new(connection, logger = nil, pool = nil)
40
49
  adapter = super
@@ -67,17 +76,11 @@ module ActiveRecord
67
76
  @config[:adapter_spec] = adapter_spec(@config) unless @config.key?(:adapter_spec)
68
77
  spec = @config[:adapter_spec]
69
78
 
70
- # NOTE: adapter spec's init_connection only called if instantiated here :
71
- connection ||= jdbc_connection_class(spec).new(@config, self)
72
-
73
79
  super(connection, logger, @config)
74
80
 
75
81
  # kind of like `extend ArJdbc::MyDB if self.class == JdbcAdapter` :
76
82
  klass = @config[:adapter_class]
77
83
  extend spec if spec && ( ! klass || klass == JdbcAdapter)
78
-
79
- # NOTE: should not be necessary for JNDI due reconnect! on checkout :
80
- configure_connection if respond_to?(:configure_connection)
81
84
  end
82
85
 
83
86
  # Returns the (JDBC) connection class to be used for this adapter.
@@ -96,30 +99,6 @@ module ActiveRecord
96
99
  ::ActiveRecord::ConnectionAdapters::JdbcColumn
97
100
  end
98
101
 
99
- # Retrieve the raw `java.sql.Connection` object.
100
- # The unwrap parameter is useful if an attempt to unwrap a pooled (JNDI)
101
- # connection should be made - to really return the 'native' JDBC object.
102
- # @param unwrap [true, false] whether to unwrap the connection object
103
- # @return [Java::JavaSql::Connection] the JDBC connection
104
- def jdbc_connection(unwrap = nil)
105
- java_connection = raw_connection.connection
106
- return java_connection unless unwrap
107
- connection_class = java.sql.Connection.java_class
108
- begin
109
- if java_connection.wrapper_for?(connection_class)
110
- return java_connection.unwrap(connection_class) # java.sql.Wrapper.unwrap
111
- end
112
- rescue Java::JavaLang::AbstractMethodError => e
113
- ArJdbc.warn("driver/pool connection impl does not support unwrapping (#{e})")
114
- end
115
- if java_connection.respond_to?(:connection)
116
- # e.g. org.apache.tomcat.jdbc.pool.PooledConnection
117
- java_connection.connection # getConnection
118
- else
119
- java_connection
120
- end
121
- end
122
-
123
102
  # Locate the specialized (database specific) adapter specification module
124
103
  # if one exists based on provided configuration data. This module will than
125
104
  # extend an instance of the adapter (unless an `:adapter_class` provided).
@@ -282,202 +261,15 @@ module ActiveRecord
282
261
  return nil, nil
283
262
  end
284
263
 
285
- # @override
286
- def active?
287
- @connection.active?
288
- end
289
-
290
- # @override
291
- def reconnect!
292
- @connection.reconnect! # handles adapter.configure_connection
293
- @connection
294
- end
295
-
296
- # @override
297
- def disconnect!
298
- @connection.disconnect!
299
- end
300
-
301
- # @note Used on AR 2.3 and 3.0
302
- # @override
303
- def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
304
- id = execute(sql, name)
305
- id_value || id
306
- end
307
-
308
264
  def columns(table_name, name = nil)
309
265
  @connection.columns(table_name.to_s)
310
266
  end
311
267
 
312
- # Starts a database transaction.
313
- # @override
314
- def begin_db_transaction
315
- @connection.begin
316
- end
317
-
318
- # Commits the current database transaction.
319
- # @override
320
- def commit_db_transaction
321
- @connection.commit
322
- end
323
-
324
- # Rolls back the current database transaction.
325
- # @override
326
- def rollback_db_transaction
327
- @connection.rollback
328
- end
329
-
330
- # Starts a database transaction.
331
- # @param isolation the transaction isolation to use
332
- # @since 1.3.0
333
- # @override on **AR-4.0**
334
- def begin_isolated_db_transaction(isolation)
335
- @connection.begin(isolation)
336
- end
337
-
338
- # Does this adapter support setting the isolation level for a transaction?
339
- # Unlike 'plain' `ActiveRecord` we allow checking for concrete transaction
340
- # isolation level support by the database.
341
- # @param level optional to check if we support a specific isolation level
342
- # @since 1.3.0
343
- # @extension added optional level parameter
344
- def supports_transaction_isolation?(level = nil)
345
- @connection.supports_transaction_isolation?(level)
346
- end
347
-
348
- # Does our database (+ its JDBC driver) support save-points?
349
- # @since 1.3.0
350
- # @override
351
- def supports_savepoints?
352
- @connection.supports_savepoints?
353
- end
354
-
355
- # Creates a (transactional) save-point one can rollback to.
356
- # Unlike 'plain' `ActiveRecord` it is allowed to pass a save-point name.
357
- # @param name the save-point name
358
- # @return save-point name (even if nil passed will be generated)
359
- # @since 1.3.0
360
- # @extension added optional name parameter
361
- def create_savepoint(name = current_savepoint_name(true))
362
- @connection.create_savepoint(name)
363
- end
364
-
365
- # Transaction rollback to a given (previously created) save-point.
366
- # If no save-point name given rollback to the last created one.
367
- # @param name the save-point name
368
- # @since 1.3.0
369
- # @extension added optional name parameter
370
- def rollback_to_savepoint(name = current_savepoint_name(true))
371
- @connection.rollback_savepoint(name)
372
- end
373
-
374
- # Release a previously created save-point.
375
- # @note Save-points are auto-released with the transaction they're created
376
- # in (on transaction commit or roll-back).
377
- # @param name the save-point name
378
- # @since 1.3.0
379
- # @extension added optional name parameter
380
- def release_savepoint(name = current_savepoint_name(false))
381
- @connection.release_savepoint(name)
382
- end
383
-
384
- # Due tracking of save-points created in a LIFO manner, always returns
385
- # the correct name if any (last) save-point has been marked and not released.
386
- # Otherwise when creating a save-point same naming convention as
387
- # `ActiveRecord` uses ("active_record_" prefix) will be returned.
388
- # @return [String] the current save-point name
389
- # @since 1.3.0
390
- # @override
391
- def current_savepoint_name(compat = true)
392
- open_tx = open_transactions
393
- return "active_record_#{open_tx}" if compat # by default behave like AR
394
-
395
- sp_names = @connection.marked_savepoint_names
396
- sp_names.last || "active_record_#{open_tx}"
397
- # should (open_tx- 1) here but we play by AR's rules as it might fail
398
- end unless ArJdbc::AR42
399
-
400
- # @note Same as AR 4.2 but we're allowing an unused parameter.
401
- # @private
402
- def current_savepoint_name(compat = nil)
403
- current_transaction.savepoint_name # unlike AR 3.2-4.1 might be nil
404
- end if ArJdbc::AR42
405
-
406
268
  # @override
407
269
  def supports_views?
408
270
  @connection.supports_views?
409
271
  end
410
272
 
411
- # Executes a SQL query in the context of this connection using the bind
412
- # substitutes.
413
- # @param sql the query string (or AREL object)
414
- # @param name logging marker for the executed SQL statement log entry
415
- # @param binds the bind parameters
416
- # @return [ActiveRecord::Result] or [Array] on **AR-2.3**
417
- # @override available since **AR-3.1**
418
- def exec_query(sql, name = 'SQL', binds = [])
419
- if sql.respond_to?(:to_sql)
420
- sql = to_sql(sql, binds); to_sql = true
421
- end
422
- if prepared_statements?
423
- log(sql, name, binds) { @connection.execute_query(sql, binds) }
424
- else
425
- sql = suble_binds(sql, binds) unless to_sql # deprecated behavior
426
- log(sql, name) { @connection.execute_query(sql) }
427
- end
428
- end
429
-
430
- # Executes an insert statement in the context of this connection.
431
- # @param sql the query string (or AREL object)
432
- # @param name logging marker for the executed SQL statement log entry
433
- # @param binds the bind parameters
434
- # @override available since **AR-3.1**
435
- def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
436
- if sql.respond_to?(:to_sql)
437
- sql = to_sql(sql, binds); to_sql = true
438
- end
439
- if prepared_statements?
440
- log(sql, name || 'SQL', binds) { @connection.execute_insert(sql, binds) }
441
- else
442
- sql = suble_binds(sql, binds) unless to_sql # deprecated behavior
443
- log(sql, name || 'SQL') { @connection.execute_insert(sql) }
444
- end
445
- end
446
-
447
- # Executes a delete statement in the context of this connection.
448
- # @param sql the query string (or AREL object)
449
- # @param name logging marker for the executed SQL statement log entry
450
- # @param binds the bind parameters
451
- # @override available since **AR-3.1**
452
- def exec_delete(sql, name, binds)
453
- if sql.respond_to?(:to_sql)
454
- sql = to_sql(sql, binds); to_sql = true
455
- end
456
- if prepared_statements?
457
- log(sql, name || 'SQL', binds) { @connection.execute_delete(sql, binds) }
458
- else
459
- sql = suble_binds(sql, binds) unless to_sql # deprecated behavior
460
- log(sql, name || 'SQL') { @connection.execute_delete(sql) }
461
- end
462
- end
463
-
464
- # # Executes an update statement in the context of this connection.
465
- # @param sql the query string (or AREL object)
466
- # @param name logging marker for the executed SQL statement log entry
467
- # @param binds the bind parameters
468
- # @override available since **AR-3.1**
469
- def exec_update(sql, name, binds)
470
- if sql.respond_to?(:to_sql)
471
- sql = to_sql(sql, binds); to_sql = true
472
- end
473
- if prepared_statements?
474
- log(sql, name || 'SQL', binds) { @connection.execute_update(sql, binds) }
475
- else
476
- sql = suble_binds(sql, binds) unless to_sql # deprecated behavior
477
- log(sql, name || 'SQL') { @connection.execute_update(sql) }
478
- end
479
- end
480
-
481
273
  # Similar to {#exec_query} except it returns "raw" results in an array
482
274
  # where each rows is a hash with keys as columns (just like Rails used to
483
275
  # do up until 3.0) instead of wrapping them in a {#ActiveRecord::Result}.
@@ -506,22 +298,6 @@ module ActiveRecord
506
298
  exec_query_raw(sql, name, binds).map!(&:values)
507
299
  end
508
300
 
509
- if ActiveRecord::VERSION::MAJOR > 3 # expects AR::Result e.g. from select_all
510
-
511
- # @private
512
- def select(sql, name = nil, binds = [])
513
- exec_query(to_sql(sql, binds), name, binds)
514
- end
515
-
516
- else
517
-
518
- # @private
519
- def select(sql, name = nil, binds = []) # NOTE: only (sql, name) on AR < 3.1
520
- exec_query_raw(to_sql(sql, binds), name, binds)
521
- end
522
-
523
- end
524
-
525
301
  # Executes the SQL statement in the context of this connection.
526
302
  # The return value from this method depends on the SQL type (whether
527
303
  # it's a SELECT, INSERT etc.). For INSERTs a generated id might get
@@ -595,11 +371,6 @@ module ActiveRecord
595
371
  ( key = primary_key(table) ) ? [ key, nil ] : nil
596
372
  end
597
373
 
598
- # @override
599
- def primary_key(table)
600
- primary_keys(table).first
601
- end
602
-
603
374
  # @override
604
375
  def primary_keys(table)
605
376
  @connection.primary_keys(table)
@@ -662,19 +433,6 @@ module ActiveRecord
662
433
  end if ActiveRecord::VERSION::MAJOR < 3 ||
663
434
  ( ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR < 1 )
664
435
 
665
- def translate_exception(e, message)
666
- # we shall not translate native "Java" exceptions as they might
667
- # swallow an ArJdbc / driver bug into a AR::StatementInvalid ...
668
- return e if e.is_a?(NativeException) # JRuby 1.6
669
- return e if e.is_a?(Java::JavaLang::Throwable)
670
-
671
- case e
672
- when SystemExit, SignalException, NoMemoryError then e
673
- # NOTE: wraps AR::JDBCError into AR::StatementInvalid, desired ?!
674
- else super
675
- end
676
- end
677
-
678
436
  # Take an id from the result of an INSERT query.
679
437
  # @return [Integer, NilClass]
680
438
  def last_inserted_id(result)
Binary file
@@ -33,6 +33,12 @@ module ActiveRecord
33
33
  JdbcTypeConverter.new(supported_data_types).choose_best_types
34
34
  end
35
35
 
36
+ def time_in_default_timezone(value)
37
+ value = value.to_time if value.respond_to? :to_time
38
+
39
+ ActiveRecord::Base::default_timezone == :utc ? value.utc : value.getlocal
40
+ end
41
+
36
42
  # @deprecated no longer used - only kept for compatibility
37
43
  def set_native_database_types
38
44
  ArJdbc.deprecate "set_native_database_types is no longer used and does nothing override native_database_types instead"
data/lib/arjdbc/jdbc.rb CHANGED
@@ -31,7 +31,7 @@ module ArJdbc
31
31
  end
32
32
 
33
33
  def deprecate(message, once = nil) # adds a "DEPRECATION WARNING: " prefix
34
- ::ActiveSupport::Deprecation.warn(message, caller) || true if warn?(message, once)
34
+ ::ActiveSupport::Deprecation.warn(message, caller_locations) || true if warn?(message, once)
35
35
  end
36
36
 
37
37
  private
@@ -56,4 +56,4 @@ module ArJdbc
56
56
  else
57
57
  require 'arjdbc/discover'
58
58
  end
59
- end
59
+ end