-
Notifications
You must be signed in to change notification settings - Fork 392
Rails 8.0 Support, Postgres fixes #1222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
64021ef
49a13bc
dab401b
b6a1bc3
a3a866f
0131de7
c687b0c
376e562
dfd7620
246a640
84ca553
dc722cc
2b7118d
7c62084
6a4a88f
3a3e045
0286957
9929c0a
eb8975b
d4a6b20
974f9d4
e9fe057
84b926e
58068df
924b346
95d6cd6
0eda888
fda88d0
ccde2eb
5bfebe0
cb595b7
1831186
c672e9f
9accad2
7e6d672
bbeafdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "active_model/type/helpers/time_value" | ||
|
|
||
| # The caller only handles ArgumentError as a failure, | ||
| # but JRuby raises TypeError for invalid formats in Time.new() (non-standard), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to have a JRuby bug reference here so we can revert this patch when JRuby gets fixed. |
||
| # which isn't handled by the caller. | ||
| # We just return nil here as it will result in fallback parsing, same as raising. | ||
| module ActiveModel | ||
| module Type | ||
| module Helpers | ||
| module TimeValue | ||
| module JRubyCompat | ||
| private | ||
| def fast_string_to_time(string) | ||
| super | ||
| rescue TypeError | ||
| nil | ||
| end | ||
| end | ||
| prepend JRubyCompat | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,16 @@ protected JdbcResult(ThreadContext context, RubyClass clazz, RubyJdbcConnection | |
| processResultSet(context, resultSet); | ||
| } | ||
|
|
||
| // HACK: Needed for postgres to be able to return a sane result type instead of just a RubyFixnum | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to figure out something better than a HACK for this. Note also concerns in the same commit about this not being the best impl. Let's figure out the best impl. |
||
| protected JdbcResult(ThreadContext context, RubyClass clazz, RubyJdbcConnection connection) { | ||
| super(context.runtime, clazz); | ||
|
|
||
| values = newArray(context); | ||
| this.connection = connection; | ||
| columnNames = new RubyString[0]; | ||
| columnTypes = new int[0]; | ||
| } | ||
|
|
||
| /** | ||
| * Builds a type map for creating the AR::Result, most adapters don't need it | ||
| * @param context which thread this is running on. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,7 @@ | |
| import java.sql.Types; | ||
|
|
||
| import arjdbc.util.PG; | ||
| import org.jruby.Ruby; | ||
| import org.jruby.RubyArray; | ||
| import org.jruby.RubyClass; | ||
| import org.jruby.RubyHash; | ||
| import org.jruby.RubyModule; | ||
| import org.jruby.RubyNumeric; | ||
| import org.jruby.RubyString; | ||
| import org.jruby.*; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style concern: prefer explicit imports until there's at least ten of them. |
||
| import org.jruby.anno.JRubyMethod; | ||
| import org.jruby.runtime.Block; | ||
| import org.jruby.runtime.Helpers; | ||
|
|
@@ -39,6 +33,9 @@ public class PostgreSQLResult extends JdbcResult { | |
| // These are needed when generating an AR::Result | ||
| private final ResultSetMetaData resultSetMetaData; | ||
|
|
||
| // An optional number of updated rows | ||
| private final long cmdTuples; | ||
|
|
||
| /********* JRuby compat methods ***********/ | ||
|
|
||
| static RubyClass createPostgreSQLResultClass(ThreadContext context, RubyClass postgreSQLConnection) { | ||
|
|
@@ -64,13 +61,35 @@ static PostgreSQLResult newResult(ThreadContext context, RubyClass clazz, Postg | |
| return new PostgreSQLResult(context, clazz, connection, resultSet); | ||
| } | ||
|
|
||
| /** | ||
| * Generates a new empty PostgreSQLResult object with a given number of updates | ||
| * @param context current thread context | ||
| * @param clazz metaclass for this result object | ||
| * @param updateCount the number of updated items | ||
| * @return an instantiated result object | ||
| * @throws SQLException throws! | ||
| */ | ||
| static PostgreSQLResult newEmptyResult(ThreadContext context, RubyClass clazz, PostgreSQLRubyJdbcConnection connection, | ||
| long updateCount) { | ||
| return new PostgreSQLResult(context, clazz, connection, updateCount); | ||
| } | ||
|
|
||
| /********* End JRuby compat methods ***********/ | ||
|
|
||
| private PostgreSQLResult(ThreadContext context, RubyClass clazz, RubyJdbcConnection connection, | ||
| ResultSet resultSet) throws SQLException { | ||
| super(context, clazz, connection, resultSet); | ||
|
|
||
| resultSetMetaData = resultSet.getMetaData(); | ||
| cmdTuples = -1; | ||
| } | ||
|
|
||
| private PostgreSQLResult(ThreadContext context, RubyClass clazz, RubyJdbcConnection connection, | ||
| long updateCount) { | ||
| super(context, clazz, connection); | ||
|
|
||
| resultSetMetaData = null; | ||
| cmdTuples = updateCount; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -107,7 +126,10 @@ protected IRubyObject columnTypeMap(final ThreadContext context) throws SQLExcep | |
| runtime.newFixnum(mod), | ||
| name); | ||
|
|
||
| if (!type.isNil()) types.fastASet(name, type); | ||
| if (!type.isNil()) { | ||
| types.fastASet(name, type); | ||
| types.fastASet(runtime.newFixnum(i), type); | ||
| } | ||
| } | ||
|
|
||
| return types; | ||
|
|
@@ -258,12 +280,10 @@ public IRubyObject aref(ThreadContext context, IRubyObject rowArg) { | |
| return resultHash; | ||
| } | ||
|
|
||
| // Note: this is # of commands (insert/update/selects performed) and not number of rows. In practice, | ||
| // so far users always just check this as to when it is 0 which ends up being the same as an update/insert | ||
| // where no rows were affected...so wrong value but the important value will be the same (I do not see | ||
| // how jdbc can do this). | ||
| // Note: This is probably not the best implementation, | ||
| // but it is better than always returning 0 on non-value-returning ops. | ||
| @PG @JRubyMethod(name = {"cmdtuples", "cmd_tuples"}) | ||
| public IRubyObject cmdtuples(ThreadContext context) { | ||
| return values.isEmpty() ? context.runtime.newFixnum(0) : aref(context, context.runtime.newFixnum(0)); | ||
| return cmdTuples != -1 ? context.runtime.newFixnum(cmdTuples) : values.length(context); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exclude :test_url_invalid_adapter, "sqlserver is not a built-in adapter, so rails complains when validating the error" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very annoying that the Rails tests implicitly require there be no other adapters. This warrants a patch to Rails imho. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exclude :test_url_invalid_adapter, "sqlserver is not a built-in adapter, so rails complains when validating the error" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| exclude :test_some_time, 'intermittent failures, leaks thread, fires at high frequency' | ||
| exclude :test_connection_pool_starts_reaper, 'intermittent failures, leaks thread, fires at high frequency' | ||
| exclude :test_reaper_works_after_pool_discard, 'deadlocks under JDBC due to high frequency discard' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know why this deadlocks? Of course we have lots of excludes but this seems like one we should try to fix rather than excluding. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exclude :test_url_invalid_adapter, "sqlserver is not a built-in adapter, so rails complains when validating the error" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exclude :test_url_invalid_adapter, "sqlserver is not a built-in adapter, so rails complains when validating the error" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be temporary; we need to work with rbs folks to get a release out with JRuby support.