ActiveRecord-JDBC is coming along

The ActiveRecord-JDBC adapter is rapidly maturing these days. I got the
full set of AWDwR2 migrations to run with it against MySQL last night,
and Ola Bini has gotten migrations working well against Oracle and
Firebird. We also have SQL Server support running most of our test
cases (under non-Windows environments too!) and have started adding
support for Derby and HSQLDB (Java-based DBs). Things are looking very
good.

However we have a very small request. In order for
ActiveRecord-JDBC to be usable, users must manually modify the list of
supported adapters in activerecord.rb, adding “jdbc” to the list.

We
would be very thankful if there were a way to include the “jdbc” string
in that list in future releases. That would allow users to get up and
running just by installing “rails” and “ActiveRecord-JDBC” gems,
requiring no additional steps. I believe the currently-listed databases
also have external requirements, so adding “jdbc” seems
reasonable…especially since we’ll never need to add anything else;
“jdbc” support covers all databases at once.

Is this a reasonable request?

Also FYI, we’d like to
work with you folks to find a way to refactor out some of the DDL logic
in the stock adapters so we can reuse it in the JDBC adapter. With JDBC
we get very nice support for straightforward queries, updates, typing,
and precision without any additional work, but there’s no facilities
for generating DDL. This means that without us copying the core Rails
DDL logic (as we’re doing now) or abstracting it out into a callable
module (which we’d like), migrations would not work with the JDBC
adapter. I’ll start a separate discussion on that once we’ve got some
idea how it could look, but I wanted to let you know it’s coming.

However we have a very small request. In order for ActiveRecord-JDBC to be
usable, users must manually modify the list of supported adapters in
activerecord.rb, adding "jdbc" to the list.

We would be very thankful if there were a way to include the "jdbc" string
in that list in future releases. That would allow users to get up and
running just by installing "rails" and "ActiveRecord-JDBC" gems, requiring
no additional steps. I believe the currently-listed databases also have
external requirements, so adding "jdbc" seems reasonable...especially since
we'll never need to add anything else; "jdbc" support covers all databases
at once.

Is this a reasonable request?

There's already provision for that in the initializer:

config.connection_adapters= ["jdbc"]

It seems like it's meant to work ....

    def set_connection_adapters
      Object.const_set("RAILS_CONNECTION_ADAPTERS",
configuration.connection_adapters) if
configuration.connection_adapters
    end

Is there a reason that that doesn't work?

I wasn’t aware of that particular setting, but it does not appear to work under Rails 1.1.6, at any rate. I added it to both environment.rb and environments/production.rb, and it seemed to have no effect. Am I doing something wrong?

As far as I can tell, it seems that the database initialization happens early enough in the process that we can’t add to the list of adapters before it blows up.

I wasn't aware of that particular setting, but it does not appear to work
under Rails 1.1.6, at any rate. I added it to both environment.rb and
environments/production.rb, and it seemed to have no effect. Am I doing
something wrong?

As far as I can tell, it seems that the database initialization happens
early enough in the process that we can't add to the list of adapters before
it blows up.

Yeah, I can't see how that'd work at all ;), seems no one's tried to
use it before ;).

David added it, the ticket's available here:

http://dev.rubyonrails.org/ticket/1958

So it seems that setting it in environment rb before the initializer
runs lets you override that behaviour. The config. option doesn't
seem to work at all. Perhaps david or stefan could chime in?

Yeah, I can't see how that'd work at all ;), seems no one's tried to
use it before ;).

David added it, the ticket's available here:

http://dev.rubyonrails.org/ticket/1958

So it seems that setting it in environment rb before the initializer
runs lets you override that behaviour. The config. option doesn't
seem to work at all. Perhaps david or stefan could chime in?

So, the ideal fix would be that that config value actually worked, in
the meantime if you set the constant above the initializer block, that
*should* work...

Michael Koziarski wrote:

Yeah, I can't see how that'd work at all ;), seems no one's tried to
use it before ;).

David added it, the ticket's available here:

http://dev.rubyonrails.org/ticket/1958

So it seems that setting it in environment rb before the initializer
runs lets you override that behaviour. The config. option doesn't
seem to work at all. Perhaps david or stefan could chime in?
    
So, the ideal fix would be that that config value actually worked, in
the meantime if you set the constant above the initializer block, that
*should* work...

Hi,

Yes, I've tried both ways. Of course, setting this value above the initializer block works (and we have a plugin version that modifies environment.rb), but this is still a manual extra step. (And at least to me it feels slightly hackish to change stuff above the "official" user configurable parts.)

The optimal would be that the default connection adapters include jdbc from the beginning. As Charles noted; you're already include other adapters with external dependencies here.

Regards

Yes, I’ve tried both ways. Of course, setting this value above the
initializer block works (and we have a plugin version that modifies
environment.rb), but this is still a manual extra step. (And at least to
me it feels slightly hackish to change stuff above the “official” user

configurable parts.)

I’ve tried setting RAILS_CONNECTION_ADAPTERS just about everywhere in the environment files and it just doesn’t want to work. Perhaps I’m doing something wrong, but there seems to be no working mechanism for adding to the list of adapters right now.

The optimal would be that the default connection adapters include jdbc
from the beginning. As Charles noted; you’re already include other

adapters with external dependencies here.

And a reminder…once “jdbc” is in there we won’t ever bug you to add another name…“jdbc” covers all possible databases the ActiveRecord-JDBC will ever support. Pretty please? :slight_smile:

I've tried setting RAILS_CONNECTION_ADAPTERS just about everywhere in the
environment files and it just doesn't want to work. Perhaps I'm doing
something wrong, but there seems to be no working mechanism for adding to
the list of adapters right now.

Please do dig in and find that bug. I'd much rather have a working,
convenient method of doing this for all future adapters as well than to
hack something in like that now.

David Heinemeier Hansson

I was able to get the OpenBase plugin adapter working without even
putting it in the connection_adapters array. Instead, I initialized
the plugins before anything else:

Rails::Initializer.run(:load_plugins)
Rails::Initializer.run do |config|
...

I haven't had any problems running like this, as the list of adapters
is only used to load the code for the adapter ... or am I mistaken?

-Derrick