Skip to content
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

Connection Mode: JRuby/JDBC #106

Closed
plentz opened this issue Aug 5, 2011 · 11 comments
Closed

Connection Mode: JRuby/JDBC #106

plentz opened this issue Aug 5, 2011 · 11 comments
Labels

Comments

@plentz
Copy link

plentz commented Aug 5, 2011

it would be awesome if we can use activerecord-sqlserver-adapter in the same way we can use activerecord-oracle_enhanced-adapter. it automatically detects that it's in a jruby environment and rely to jdbc mode to connect to the database.

@metaskills
Copy link
Member

Tho I think TinyTDS is a better connection mode (which also compiles on jRuby, I am open to other connection modes. But I am not going to write them. The adapter now supports two, RubyODBC, and TinyTDS. At one time I had a connection mode for ADONET to support IronRuby. But no one in their group supported it or tested it.

Basically I have the adapter written in such a way that it would be fairly straight forward to define a connection mode and a few key delegate methods that would get the results. If someone wants to work on that, I'd be happy to detail a few key points, but they should be visible to any that look. I am also very persnickety about passing tests too. So whomever takes this on, I won't accept half way / work for me code. Thoughts?

@plentz
Copy link
Author

plentz commented Aug 5, 2011

I think that tiny_tds is a better place to put jdbc support, since more people could use it(not just raillers). What you think?

@metaskills
Copy link
Member

I'm not so sure. TinyTDS is a low level connection mode. My limited understanding of JRuby and JDBC is that these are their own low level connection modes specific to that implementation. So TinyTDS and the JDBC (JTDS?) are mutually exclusive. To me this is like asking for native ADONET for IronRuby in TinyTDS as I mentioned on the adapter issue.

Remember, the adapter is written in such a way that is just Ruby generating SQL that SQL Server likes. I made great care to not mix in core connection mode logic into the adapter. Hence it is very easy for us to adapt to alternate connection modes. I did this for the benefit of adding TinyTDS and ADONET and that simple architecture can be applied to native JDBC connections.

@plentz
Copy link
Author

plentz commented Aug 5, 2011

Well, that's the approach used by oracle-enhanced. I think it's a better approach(at least when using JRuby/JVM) since it reduce the work necessary to put it up and running(just put the jtds.jar in your classpath) and free tiny_tds users from having a platform specific dependency.

@metaskills
Copy link
Member

I hear what your saying, and what oracle-enhcanced is doing is similar to what I am talking about. Case in point, when the ADONET connection mode was in the adapter code base, it went thru the following steps.

  1. When the adapter library initialized a mode, it would require said connection mode's library. For ADONET, this was require 'System.Data'. It does this conditionally so libs that people do not want to opt into or frankly do not have on their platform are not looked for. IE, there is no System.Data on MRI, JRuby, etc, only IronRuby.

  2. In the connect method, we implement code for said connection required in step (1) to parse database.yml and make said native connection.

  3. We delegate down to a single method for giving sending SQL and getting results from said connection. This follows the pattern of a method named #handle_to_names_and_values_#{mode}. This method has to handle a few different ways of doing said task that I will not go into here.

  4. There are a few misc methods that we case the connection mode for doing native things, is the connection open, etc. Easily found by searching for cases on the @connection_mode (iirc).

An example of this can be found when I yanked the ADONET connection mode in this commit below. It has a little bit of noise, but it should be easy to see the lines specific to ADONET and the steps I mentioned above.
cbead13

So, I still assert that what I am talking about is right and that TinyTDS is not the place for this. The only thing your talking about is including a jtds.jar file and requiring it in step (1), configuring it in step (2), using it in steps (3) and (4). Which including is or not is moot. Sure it could be done, sure it could not be done. The point is that the steps I mentioned above are the ones to go thru and it should be easy for someone with the proper experience to leverage all the work I have done and shim in a native jtds connection mode in the framework I have in place.

When do I see a pull request?

@plentz
Copy link
Author

plentz commented Aug 5, 2011

You're right and I was wrong. it's really oracle-enhcanced that manages to rely on jdbc instead of using ruby-oci8. My bad, sorry. Btw, I will try to take a look and do some coding next week. If someone already coding something, please share here so we don't code the same thing twice :)

@metaskills
Copy link
Member

Good show @plentz, if at the least, we have setup a proper place for someone to come in and contribute with a proper overview. Many of these thins are in my head and not documented well since I am the only committer to the project. Hopefully I can reach out more for help and/or garner a bigger commit base. Sadly, not that many people are used to digging deep into ActiveRecord adapter's and Arel visitors. We'll see if we can fix that.

Maybe Nick Sieger would consider it or something.

@codertrader
Copy link

Late to the party - want to fill me in?

@metaskills
Copy link
Member

Everything above should spell out the details. Hop on into #rails-sqlserver on freenode if want too.

@plentz
Copy link
Author

plentz commented Oct 26, 2011

Sorry for the no-show @metaskills. I've endedup using jruby/activerecord-jdbc-adapter which pretty much dit the trick(and has "official" support at some level), so I think it isn't really necessary to put this much effort here. Maybe just a link to that project in the README will work well. What you think?

@metaskills
Copy link
Member

No worries, I am still of the opinion that this adapter is the most robust and well tested. At its heart, it is just ruby that generates the best SQL for SQL Server and underneath are two different connection modes (c extensions) RubyODBC and TinyTDS. I'd really love for someone to write a little bit of code that would add native jtds to that list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants